I am in trouble with my dice game. I have a task:
The rules of the game are the following: 1. The player rolls the dice and adds up the face values. 2. If the first roll is a 7 or 11, the player wins. 3. If the first roll is a 2, 3 or 12, the player looses. 4. If the first roll is any other number, that sum becomes the player's point. 5. To win, the player must continue rolling the dice until he/she “makes point.” 6. The player loses by rolling a 7 before the point.
1) Define WON and LOST as macros in your program. Use the values of 0 for WON and 1 for LOSE 2) Implement a function, with function prototype int rollDice( void );
rollDice( ) should use rand( ) to randomly generate a number between 1 - 6
return the number generated by rand( )
3) Implement a function, with function prototype int playGame( void );
When the player is ready to play, (s)he would use the key ENTER to roll the dice
If the user wins in his/her first roll, congratulate the player and return with WON
If the user looses in his/her first roll, congratulate the player and return with LOSE
Let the user keep playing until (s)he wins / loses, give an appropriate massage and finish the game with the last roll value.
4) Your main( ) should Call your function playGame( )
Ask the user if (s)he wants to continue playing another game, keeping track of the numbers of losses and wins
When the user decides to finish playing, display the number of wins and losses (s)he had.
Give the user an appropriate message depending on the number of wins or losses (s)he had
Return with a value of EXIT_SUCCESS
Here is what I have now, but it tells me that there are mistakes. Can anyone please help me with this task?
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#define WON 0
#define LOSE 1
int rollDice(void);
int playGame(void);
int rollDice(void) {
return ((rand() % 6) + 1);
}
int playGame(void){
int dice_1 = 0;
int dice_2 = 0;
int sum = 0;
time_t t;
srand(time(&t));
printf("ROLL THE DICE WITH [ENTER]\n");
dice_1 = rollDice();
dice_2 = rollDice();
sum = dice_1 + dice_2;
if (sum == 7 || sum == 11){
printf("Congratulations you roll %d and WON at your first try!", sum);
}
else {
printf("Your roll was %d ,you lose try agian.\n", sum);
}
return 0;
}
int main (void){
playGame();
}
The Error is (in gcc linux):
x.c:9:1: error: stray ‘\302’ in program
int rollDice(void);
^
x.c:9:1: error: stray ‘\240’ in program
x.c:10:1: error: stray ‘\302’ in program
int playGame(void);
^
x.c:10:1: error: stray ‘\240’ in program
x.c:12:1: error: stray ‘\302’ in program
int rollDice(void) {
^
x.c:12:1: error: stray ‘\240’ in program
x.c:16:1: error: stray ‘\302’ in program
int playGame(void){
^
x.c:16:1: error: stray ‘\240’ in program