Pregunta

For coursework I have to create a Roulette Wheel (European) which:

  • Read from standard input one valid bet on a single number
  • Select a winning number at random
  • Is an animation of 2 or more frames
  • Display the user bet and winning number

So far I've animated the wheel using a for loop and there is a ball that lands on a random number.

I have attempted to write some code for the user input

int bet[3];  
int result;
scanf( "%d" , &bet);
if (bet >=0 && bet <= 36); result = 1;
printf("Your bet is number %d", &bet);

When inputting a bet into the stdin console the program does not display the contents of the printf functions and just goes straight to the animation. Any suggestions or help to improve the user input would be appreciated

¿Fue útil?

Solución

You need to terminate the output with a newline to flush the output buffer

printf("Your bet is number %d\n", &bet);
//                           ^^ newline to flush output buffer

Also, you really don't need an array of 3 ints for input. A single int is enough

int bet;
scanf("%d", &bet);
// ...
printf("Your bet is number %d\n", bet);

If you want to keep the arrays of 3 ints, you need to change your code

int bet[3];  
int result;
scanf( "%d" , &bet[1]); // or &bet[0] or bet + 2
if (bet[1] >=0 && bet[1] <= 36); result = 1;
printf("Your bet is number %d", bet[1]);

Also (I noticed while editing the code above) you have an extra semicolon in your if line

if (bet >=0 && bet <= 36); result = 1;
//                       ^ ???

The result = 1; is not part of the if.

Otros consejos

if (bet >=0 && bet <= 36); result = 1;

This does not do what you want. The semicolon after your if statement is most likely a mistake. right now, result will always be set to 1.

Instead:

if (bet >=0 && bet <= 36) {
    result = 1;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top