-
Registered User
Need help
I am new to programming, and I just did this example out of my book. You pick the number, you get 6 trys, if you pick the right one you win. Anywho I want to game to repeat itself if you press Y. I know how to make the game exit if you press N. Is there C function to make the program repeat the main function?
Here is the scource code.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RANGE 100
#define TRIES 6
void main()
{
int guessme,guess,t,again;
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 if(guess>guessme)
printf("Too high!\n");
}
printf("The answer was %i.\n",guessme);
// printf("Would you like to play again? Y/N?");
// again=getche();
// if(again=='y');
// else if getche(printf("\nPress any key to exit."));
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
Popular pages
Recent additions