M
Mike
Hello,
This game will not loop. It compiles, builds, and executes fine, but
the game will not loop around no matter what I do. What is wrong with
the code? What do I have to add to make it loop till the person
selects "N" or "n".
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RANGE 10
#define TRIES 1
int rnd(int range);
void seedrnd(void);
void main()
{
int guessme,guess,t;
seedrnd();
guessme=rnd(RANGE)+1;
printf("GUESS!?!\nGuess the random number.\n");
printf("I'm thinking of a number\
between 1 and %i.\n",RANGE);
printf("Can you guess it in %i tries?\n",TRIES);
for(t=1;t<=TRIES;t++)
{
printf("Guess #%i:",t);
scanf("%i",&guess);
if(guess==guessme)
{
printf("You got it!\n");
break;
}
else if(guess<guessme)
printf("Too low!\n");
else
printf("Too high!\n");
}
printf("The answer was %i.\n",guessme);
getchar();
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
int playAgain(void)
{
char answer;
printf("Do you want to play again? Enter Y or y (yes) and N or n (no):
");
scanf("%c",&answer);
if (answer == 'Y' || answer == 'y')
{
return 1;
}
else if (answer == 'N' || answer == 'n')
{
printf("\n");
printf("Good Bye! Have A Nice Day!!!\n");
return 0;
}
else
{
printf("Do you want to play again? Enter Y or y (yes) and N or n (no):
");
scanf("%c",&answer);
}
return answer;
}
This game will not loop. It compiles, builds, and executes fine, but
the game will not loop around no matter what I do. What is wrong with
the code? What do I have to add to make it loop till the person
selects "N" or "n".
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RANGE 10
#define TRIES 1
int rnd(int range);
void seedrnd(void);
void main()
{
int guessme,guess,t;
seedrnd();
guessme=rnd(RANGE)+1;
printf("GUESS!?!\nGuess the random number.\n");
printf("I'm thinking of a number\
between 1 and %i.\n",RANGE);
printf("Can you guess it in %i tries?\n",TRIES);
for(t=1;t<=TRIES;t++)
{
printf("Guess #%i:",t);
scanf("%i",&guess);
if(guess==guessme)
{
printf("You got it!\n");
break;
}
else if(guess<guessme)
printf("Too low!\n");
else
printf("Too high!\n");
}
printf("The answer was %i.\n",guessme);
getchar();
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
int playAgain(void)
{
char answer;
printf("Do you want to play again? Enter Y or y (yes) and N or n (no):
");
scanf("%c",&answer);
if (answer == 'Y' || answer == 'y')
{
return 1;
}
else if (answer == 'N' || answer == 'n')
{
printf("\n");
printf("Good Bye! Have A Nice Day!!!\n");
return 0;
}
else
{
printf("Do you want to play again? Enter Y or y (yes) and N or n (no):
");
scanf("%c",&answer);
}
return answer;
}