i have some kind of code in the error but i have searched and looked i do not no what is wrong i am getting this erro message :error C2065: 'loop' : undeclared identifier but i thought that you did not have to id loop they are not a varibale
#include <iostream>
#include <cstdlib>

using std::cout;
using std::rand;

int flip();

int main()
{
int coinToss;
int heads, tails;

heads = 1;
tails = 0;
coinToss = 100;
for(loop=0; loop<5; loop++){
for (int toss = 0; toss < coinToss; toss++)
{
flip();
if (flip()== 1)
heads = heads + 1;
else
tails = tails + 1;
}}
return 0;
cout << "Heads appear " << heads << " times.\n";
cout << "Tails appear " << tails << " times.\n";
return 0;
}

int flip()
{
return rand() % 2;
}

You will have to declare the variable loop as int in line 14. It is treated as integer inside the for loop

for(int loop=0; loop<5; loop++){

thank you for the tips but the loop funtion is still;not working correctly wha ti want is for program to run 5 time it is till only running once
#include <iostream>
#include <cstdlib>

using std::cout;
using std::rand;

int flip();

int main()
{
int rand();
int coinToss;
int heads, tails;

heads = 1;
tails = 0;
coinToss = 10;
for(int loop=0; loop<5; loop++){
for (int toss = 0; toss < coinToss; toss++)
 {
 flip();
if (flip()== 1)
heads = heads + 1;
else
tails = tails + 1;
 }
if (flip() == 1)
 {
heads++;
 cout << "H";
 }
 else
 {
 tails++;
 cout << "T";
 }
  }
cout << "Heads appear " << heads << " times.\n";
 cout << "Tails appear " << tails << " times.\n";
 return 0;
  }

 int flip()
 {
 return rand() % 2;
  }

ok i donlt see it doing that what i want is for the coin to be flipped ten time and have the display show up of how often it is flipped for each side and then i want it to rum throu the loop and diplay ten flips 4 more time it is not doing that. this is what i am getting :
HHTTTHeads appear 26 times.
Tails appear 30 times.
Press any key to continue . . .

Move line 34 to between line 36 and 37. This brings the output statement to the end of the inner for loop but still in the outer for loop. Reset heads and tails to zero each time before starting through outer loop.

This article has been dead for over six months. Start a new discussion instead.