Code:
#include <stdio.h> //std input and output
#include <math.h> //math library
#include <stdlib.h> //standard libarary
int main (void)
{
printf("Welcome To The Roulette Wheel Simulator. \n \n");
long cash = 0; //count the number of $1 you win.
int p = 0; //probability is an integer here to allow for rand.
double probability = 0; //hasn't been used yet.
int games = 0;
//pseudo-random number generator
int counter;
for(counter = 0; counter < 1000; counter++)
{
int p = 0;
p = rand()%4737;
if(p >= 526 && counter < 1000) //continue to loop until a loss
{
cash = cash + 1; //add to cash.
}
if(p <= 526)
{
printf(" You lost at %d games\n \n You won $%d \n \n", &counter, &cash);
printf ("Press Any Key to Exit\n");
break;
}
}
getch();
}
1. Learn indentation - SourceForge.net: Indentation - cpwiki
2. && counter < 1000 will never happen, given the for loop has the same test.
3. >= 526 and <= 526 overlap at 526. It would have been better to use an else
4. &counter, &cash - you have to pay attention to what you pass to printf/scanf.
printf(" You lost at %d games\n \n You won $%ld \n \n", counter, cash);