Instructions:
1) Create a txt file called data.txt
2) Input the gems dropped count in it. To separate them, use space or enter.
INPUT SEEDS AS 50 AND BLOCKS AS 100. IF YOU WANT TO FINISH, INPUT 999
Example of data.txt file: 17 50 15 12 10 9 0 1 6 3 5 7 5 3 9 15 50 100 100 50 5 9 10 999
If you encounter errors/bugs, tell me.
Script:
#include <fstream>
#include <cmath>
using namespace std;
void read(int A[], int &n) //INPUT SEEDS AS 50 AND BLOCKS AS 100! If data ends, input 999!
{
int i, x;
x=1;
n=0;
ifstream df ("data.txt"); //name your input data file as data.txt
df>>A[0];
while(x!=0)
{
if(A[n]!=999)
{
n=n+1;
df>>A[n];
}
else
x=0;
}
df.close();
}
void calculations(int A[], int n)
{
int a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, seed, block, sum, i;
a0=0; a1=0; a2=0; a3=0; a4=0; a5=0; a6=0; a7=0; a8=0; a9=0; a10=0; a11=0; a12=0; a13=0; a14=0; a15=0;
a16=0; a17=0; a18=0; a19=0; a20=0; a21=0; a22=0; a23=0; a24=0; a25=0; seed=0; block=0;
ofstream rf ("results.txt");
for(i=0; i<n; i++)
{
if(A[i]==0)
a0=a0+1;
if(A[i]==1)
a1=a1+1;
if(A[i]==2)
a2=a2+1;
if(A[i]==3)
a3=a3+1;
if(A[i]==4)
a4=a4+1;
if(A[i]==5)
a5=a5+1;
if(A[i]==6)
a6=a6+1;
if(A[i]==7)
a7=a7+1;
if(A[i]==8)
a8=a8+1;
if(A[i]==9)
a9=a9+1;
if(A[i]==10)
a10=a10+1;
if(A[i]==11)
a11=a11+1;
if(A[i]==12)
a12=a12+1;
if(A[i]==13)
a13=a13+1;
if(A[i]==14)
a14=a14+1;
if(A[i]==15)
a15=a15+1;
if(A[i]==16)
a16=a16+1;
if(A[i]==17)
a17=a17+1;
if(A[i]==18)
a18=a18+1;
if(A[i]==19)
a19=a19+1;
if(A[i]==20)
a20=a20+1;
if(A[i]==21)
a21=a21+1;
if(A[i]==22)
a22=a22+1;
if(A[i]==23)
a23=a23+1;
if(A[i]==24)
a24=a24+1;
if(A[i]==25)
a25=a25+1;
if(A[i]==50)
seed=seed+1;
if(A[i]==100)
block=block+1;
}
rf<<"0 gems: "<<a0<<endl;
rf<<"1 gem: "<<a1<<endl;
rf<<"2 gems: "<<a2<<endl;
rf<<"3 gems: "<<a3<<endl;
rf<<"4 gems: "<<a4<<endl;
rf<<"5 gems: "<<a5<<endl;
rf<<"6 gems: "<<a6<<endl;
rf<<"7 gems: "<<a7<<endl;
rf<<"8 gems: "<<a8<<endl;
rf<<"9 gems: "<<a9<<endl;
rf<<"10 gems: "<<a10<<endl;
rf<<"11 gems: "<<a11<<endl;
rf<<"12 gems: "<<a12<<endl;
rf<<"13 gems: "<<a13<<endl;
rf<<"14 gems: "<<a14<<endl;
rf<<"15 gems: "<<a15<<endl;
rf<<"16 gems: "<<a16<<endl;
rf<<"17 gems: "<<a17<<endl;
rf<<"18 gems: "<<a18<<endl;
rf<<"19 gems: "<<a19<<endl;
rf<<"20 gems: "<<a20<<endl;
rf<<"21 gems: "<<a21<<endl;
rf<<"22 gems: "<<a22<<endl;
rf<<"23 gems: "<<a23<<endl;
rf<<"24 gems: "<<a24<<endl;
rf<<"25 gems: "<<a25<<endl;
rf<<"seeds: "<<seed<<endl;
rf<<"blocks: "<<block<<endl;
sum=a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+ a14+a15+a16+a17+a18+a19+a20+a21+a22+a23+a24+a25+se ed+block;
rf<<"Total amount of blocks broken: "<<sum;
rf.close();
}
int main()
{
int A[100000], n;
read(A, n);
calculations(A, n);
return 0;
}
Bookmarks