Dice roll functions

So I'm working on a problem from a midterm that I know I completely messed up but i'm trying to understand it but I'm having a difficult time

The major part i'm having issues is in C we are using functional programming. Now I wrote a function that I think should work but I don't think i'm calling it correctly. Basicly when i want to use a printf statement call the function and produce the number.

Any help would be nice so I can get passed this point.

Here is what I have done so far, and any questions on what i'm trying to do just ask

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
  #include<stdio.h>
#include<stdlib.h>
#include<time.h>

int diceroll(int dealRoll)	{
	int result, die1, die2;

	srand(time(0));

	die1 = rand() % 6 + 1;
	die2 = rand() % 6 + 1;

	result = die1 + die2;

	return result;
}



main()	{

	int choice, dealRoll = 0;
	
	
		printf("Enter in the bet you want: under 7 (Enter 1), over 7 (Enter 2), for 7 (Enter 3):   ");
		scanf_s("%i", &choice);

		//dealRoll = diceRoll(i);
		printf("Shake, Shake, the dealer rolls %d", diceRoll(dealRoll));
		
		
	


	system("pause");
}
The major part i'm having issues is in C we are using functional programming.

Well, that would certainly be interesting.



diceRoll is not the same as diceroll.

main should return type int.

srand should be invoked one time, so it should probably be invoked in main and not diceroll.

What role do you see dealRoll playing here? diceroll does nothing with the value fed to it and it seems to serve no purposed in main other than as fodder to be fed to diceroll.

scanf_s is not part of the standard C library.
Last edited on
thought I would try to clean up/shorten what you have and call the function it looked like you wanted to call:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int DiceRoll() {
	return (rand()%6+1)+(rand()%6+1);
}

int main() {
	int choice;
	srand(time(0));
	printf("Enter in the bet you want: under 7 (Enter 1), over 7 (Enter 2), for 7 (Enter 3): ");
	scanf("%i",&choice);
	printf("Shake, Shake, the dealer rolls %d",DiceRoll());
	system("pause");
}


I left line 10 and 13 because it looked like you plan on using them later in the program to tell the user if they win or not.
note: system("pause"); only works under windows as far as I know. doesn't work with Linux for sure.
Topic archived. No new replies allowed.