Hi! I have this program and it is running but there is an error..I think I might need to use arrays or something to correct it but we have not covered arrays yet. Is there any way for me to fix it with very basic C++?
PROBLEM: When the program runs I get the same random number printed multiple times instead of getting different number with every iteration of the loop.
"Ask the user how many times they want to roll a single six-sided die. Use a loop to simulate rolling the die (i.e. each time it generates a number from 1 to 6). Print the result of each roll. Also, using a running total, print the sum of all rolls."
int random=0;
int rolldie=0;
int counter=0;
int total=0;
cout<<"Run task 2 (y/n)?"<<endl;
useranswer=GetChar();
if (useranswer=='y')
{
cout<<"How many times do you want to roll a die?"<<endl;
rolldie=GetInt();
for (counter=1;rolldie>=counter; counter++)
{
srand(time(0));
random=1+rand()%6; cout<<counter<<" time rolling a die: "<<random<<endl;//i think this line might be incorrect
total=total+random;
}
cout<<"The sum of all rolls is: "<<total<<endl;
}
srand(time(0));
for (counter=1;rolldie>=counter; counter++)
{
random=1+rand()%6;
cout<<counter<<" time rolling a die: "<<random<<endl; //i think this line might be incorrect
total=total+random;
}