1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include<iostream>
#include<cstdlib>//rand and srand
#include<ctime>
using namespace std;
int main()
{srand(time(0));//using current time
int ones,twos,threes,fours,fives,sixes;//declare each possible number
int roll, r;
char goagain;
do{//loop, do this while goagain = y
ones=twos=threes=fours=fives=sixes=0; //all set to 0
cout<<"\nHow many rolls: ";
cin>> r;
for(int i=1; i<= r; i++) //up to the number of rolls user inputs (r)
{
roll = rand()%6+1;//between 1 and 6, rand() randomizes a number then puts into % equation
cout<< "\nYou rolled a "<< roll;
if(roll==1)ones++;//if roll = 1, counter adds +1
if(roll==2)twos++;
if(roll==3)threes++;
if(roll==4)fours++;
if(roll==5)fives++;
if(roll==6)sixes++;
}
cout<<"\n\n1 - "<<ones//prints out how many times each number was outputted
<<"\n2 - "<<twos
<<"\n3 - "<<threes
<<"\n4 - "<<fours
<<"\n5 - "<<fives
<<"\n6 - "<<sixes;
if(ones > twos, threes, fours, fives, sixes){
cout << "\nYou should vote for 1, because it rolled " << ones << " times." << endl;
} else if(twos > ones, threes, fours, fives, sixes){
cout << "You should vote for 2, because it rolled " << twos << " times." << endl;
} else if(threes > ones, twos, fours, fives, sixes){
cout << "You should vote for 3, because it rolled " << threes << " times." << endl;
} else if(fours > ones, twos, threes, fives, sixes){
cout << "You should vote for 4, because it rolled " << fours << " times." << endl;
} else if(fives > ones, twos, threes, fours, sixes){
cout << "You should vote for 5, because it rolled " << fives << " times." << endl;
} else if(sixes > ones, twos, threes, fours, fives){
cout << "You should vote for 6, because it rolled " << sixes << " times." << endl;
} else {
cout << "\n I am not sure what you should vote for.";
}
cout<<"\nGo again? y/n ";//prompt user at the end
cin>>goagain;
}
while(goagain=='y');//otherwise program ends
cout<< "\n\n";
return 0;
}
|