#include <time.h>
int main()
{
int Die1; /*Random Number 1-6*/
int Die2; /*Random Number 1-6*/
int Total; /*Total value of the two dice*/
int chipBalance=100; /*Number of chips player has*/
int bet;
/*Begin round of betting*/
printf("Enter bet between 1 and 100\n");
scanf("%d\n", &bet);
/* Generate two random numbers 1-6 for the two dice*/
srand((unsigned)time(NULL));
Die1 = 1 + (rand() % 6); {
printf("Die 1 value is: %d\n", Die1); }
Die2 = 1 + (rand() % 6); {
printf("Die 2 value is: %d\n\n", Die2); }
/* Show the total value of the two dice */
Total= Die1 + Die2; {
printf("Total value is: %d\n\n", Total); }
/* Display win, loss or point message for first throw */
if (Total == 7 || Total == 11) {
printf("Congratulations, you win!\n\n");
chipBalance=(chipBalance+bet);
printf("Chip Balance is: %i\n\n", chipBalance); }
elseif (Total == 2 || Total == 3 || Total == 12) {
printf("Sorry, you lose.\n\n");
chipBalance=(chipBalance-bet);
printf("Chip Balance is: %i\n\n", chipBalance); }
elseif (Total == 4 || Total == 5 || Total == 6 || Total == 8 || Total == 9 || Total == 10) {
printf("Point to make is: %d\n", Total); }
if (chipBalance<=0) {
printf("Sorry, you're out of money!\n\n"); }
while (Total == 4 || Total == 5 || Total == 6 || Total == 8 || Total == 9 || Total == 10)
srand((unsigned)time(NULL));
Die1 = 1 + (rand() % 6); {
printf("Die 1 value is: %d\n", Die1); }
Die2 = 1 + (rand() % 6); {
printf("Die 2 value is: %d\n\n", Die2); }
printf("Thanks for playing!\n\n");
return 0;
}
1. For some reason when the user inputs a bet amount, it makes the user put in two values before it will actually continue. What's the fix for this?
2. How do I alter scanf() for the bet so that ONLY 1-100 can be entered?
3. How do I do a while loop so that when the numbers 4, 5, 6, 8, 9 or 10 are rolled the first time, it rolls again? It's currently not working.