Number of questions

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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); }
		else if (Total == 2 || Total == 3 || Total == 12) {
			printf("Sorry, you lose.\n\n"); 
			chipBalance=(chipBalance-bet); 
			printf("Chip Balance is: %i\n\n", chipBalance); }
		else if (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.

For the first issue I found this explanation: http://c-faq.com/stdio/scanfhang.html
That was perfect! Thanks, easy fix for that part, guess it was the easiest question to answer :P
Last edited on
Topic archived. No new replies allowed.