This is my code
/*---------------
Include Section
----------------*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int guess (int atmpt);
[b]int DN;[/b]
/*--------------------------- main function --------------------------------
Purpose: initiate game
Returns: prompt for random number and request to play again
----------------------------------------------------------------------------*/
int
main( ){
char again;
int y;
int n;
int atmpt;
again = y;
while (again == y) {
printf("Guess a number between 1 and %i \n You have 4 guesses to find the number \n\n ",DN);
guess(atmpt);
printf("Would you like to play again (y/n)?\n");
scanf("%d",&again);
return (EXIT_SUCCESS);
}
/*--------------------------- guess function --------------------------------
Purpose: express accuracy of guesses and show when all guesses have been used up
Returns: hint or express success or failure of the game and turns left
----------------------------------------------------------------------------*/
int
guess(int atmpt){
int counter;
int num;
counter = 0;
num=rand( )%DN+1;
while (counter <= 4);
printf("?: \n");
scanf("%d",&atmpt);
if (atmpt == num)
printf("Hooray! You win! \n");
counter = 5;
else if (counter == 4)
printf("Sorry you lose. The number was: %i \n\n", num);
[b] else
print("Wrong number - Try again \n\n");[/b]
if (atmpt < num)
printf("Number is larger \n\n");
[b] else
printf("Number is smaller \n\n");[/b]
counter =+ 1;
printf("Number of guesses left is %i", 4-counter);
while ((num = getchar( )) != EOF && num != '\n');
return (EXIT_SUCCESS);
}
and these are my input and errors
~$ gcc [b]-DN=100[/b] game.c game.c: In function 'main': [u]game.c:36:3: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'char *' [-Wformat][/u] game.c: In function 'guess': [u]game.c:57:3: error: 'else' without a previous 'if'[/u] game.c: In function 'main': game.c:69:1: error: expected declaration or statement at end of input

New Topic/Question
Reply




MultiQuote







|