#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
double toss;
double rem;
double prob1 ;
double prob2;
double prob3;
double prob4;
double prob5;
double prob6;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
int count6 = 0;
srand(time(NULL));
cout << "Choose an amount of tosses you would like to try: ";
while(cin >> toss){
for(int i = 0; i < toss; i++){
rem = rand()%6+1;
if(rem == 1){
count1++;
}
elseif(rem == 2){
count2++;
}
elseif(rem == 3){
count3++;
}
elseif(rem == 4){
count4++;
}
elseif(rem == 5){
count5++;
}
elseif(rem == 6){
count6++;
}
else{
cout << "\nSomething went wrong, sorry.\n";
}
}
//These probability variables are getting the percentage for each--
//side of the die. I'm thinking my problem lies around here.
prob1 = count1/toss;
cout << "\nProbability for 1: " << prob1 << "%";
prob2 = count2/toss;
cout << "\nProbability for 2: " << prob2 << "%";
prob3 = count3/toss;
cout << "\nProbability for 3: " << prob3 << "%";
prob4 = count4/toss;
cout << "\nProbability for 4: " << prob4 << "%";
prob5 = count5/toss;
cout << "\nProbability for 5: " << prob5 << "%";
prob6 = count6/toss;
cout << "\nProbability for 6: " << prob6 << "%";
}
}
I want to input a number of tosses, then calculate how many times each side of the die was chosen. Im using a random number generator, but im not too sure I have everything correct. I feel like im using way too many variables. We haven't learned how to use arrays in my class, so we're stuck with for loops at the moment.
I would really appreciate some help in understanding this. Thanks in advance!