-
October 31st, 2009, 05:29 PM
#1
I have no idea why this isnt working...
I compiled this code without any problem, the program runs but when I enter a value nothing happens. No error message or anything, the program essentially freezes. I'm thought it might have gotten stuck in the for loop in Flip(n) but that isnt called until the second cout statement and it doesnt even get that far...Any help would be greatly appreciated.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int Flip( int in );
int main(void)
{
srand( time(0) );
int ntimes = 0;
int YN = 0;
do{
cout << "how many times do you want a coin to be tossed?" << endl ;
cin >> ntimes ;
cout << "Out of " << ntimes << " tosses " << Flip(ntimes) << " came out heads"<< endl ;
cout << " would you like to repeat the experiment? 1 for yes and 0 for no" << endl ;
cin >> YN ;
}while (YN != 0);
cout << "ok. goodbye." << endl ;
return 0;
}
int Flip( int n )
{
int iToss = 0;
int iAnswer = 0;
int iA = 0;
for (iA = 0; iA = n; iA++)
{
iToss = (rand()%2);
iAnswer = iAnswer + iToss;
}
return iAnswer;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|