Ok before I ask my question here, please understand that I am totally new to C and I don't know a dang thing compared to most of you so please look at my code and laugh your arses off then if you can still see from the tears in your eyes from laughing see if you can tell me where I am screwing this up....The code compiles and runs fine, my problem is I dont know how to get the game to repeat, it just keeps ending. It also keeps allowing guess's after the number has been found
PS this is the first attempt at writing code so be gentle lol =)
//************************************************
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <conio.h>
#define RANGE 100
#define TRIES 10
#define TRUE 1
#define FALSE !TRUE
int rnd(int range);
void seedrnd(void);
void main()
{
int guessme,guess,numberTries,keepPlaying;
char c;
seedrnd();
guessme=rnd(RANGE);
printf("********************************** GUESS!?! *******\
*****************************\n*************\
************* {Guess The Random Number} ***************************\n");
printf("I am thinking of a number between 1 and %i.\n\n",RANGE);
printf("Can you guess it in %i tries or less?\n\n",TRIES);
keepPlaying=TRUE;
numberTries=1;
while(numberTries<=TRIES)
{
printf("Guess #%i:",numberTries);
scanf("%i",&guess);
numberTries++;
if(guess==guessme)
{
printf("You got it!\n\n");
}
else if(guess<guessme)
printf("Sorry to low!\n");
else
printf("Sorry to High!\n");
}
printf("The answer was %i!\n",guessme);
// Somewhere in this section I need to edit, I get the Yes or No
// but program ends on either response, also it keeps allowing guess's
// after the correct number is found.
keepPlaying=1;
while(keepPlaying<=TRIES)
{
printf("Wanna Play again\n");
printf("Type (Y) for Yes, (N) for No!\n");
keepPlaying++;
c=toupper(getch());
if(c=='Y');
{
printf("Goodluck\n");
keepPlaying=TRUE;
break;
}
}
}
// This section Interger Range
int rnd(int range)
{
int r;
r=rand()⦥
return(r);
}
// This section Seed Random Number using NULL
void seedrnd()
{
srand((unsigned)time(NULL));
}



LinkBack URL
About LinkBacks


