vendredi 30 janvier 2015

first program in c, random number generator and have them guess it

i took java for a while and i'm switching over to C, this is my first program and i have to get a number over 99 from the user, create a random number from 1 to that number, and try to have them guess it. i'm having some troubles trying to get it to compile. can i get general tips and help as to what i'm doing wrong(why it won't compile)?



#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {

char goAgain = "y";
int theNum = 1;
int guess;

do{
do{
printf("Enter a number over 99");
scan f("%d", &theNum);
if(theNum <= 99) {
printf("Please enter a number over 99");
}
}while(theNum <= 99);
do{

srand(time(NULL));
theNum = rand() % theNum+1;
printf("Please enter a guess");
scanf("%d", &guess);
if(guess > theNum) {
printf("Too high");
}
if(guess < theNum) {
printf("Too high");
}
else {
printf("That's correct!");
}
}while(theNum != guess);

printf("Would you like to play again? (y/n)");
goAgain = getchar();
while(getchar == "\n"){
}
}while(goAgain == "y");
return(0);
}




Aucun commentaire:

Enregistrer un commentaire