Hey Guys, I really need some help here. I am new to programming and I reading a book that focused on people like me...."beginners, noobs..." you know. I have been stuck working on an exercise for the last 5 days and I have gotten it to what I would like for it to be but I AM STUCK!!!
The exercise requires me to insert a count of how many times the user guesses before they get the correct answer.
I get the one count, but for some reason I can get it to increment.
I have looked around for the answer but the ones that I have found, touch on subjects that the book has not touched upon.
Please if you can assist, it would be great.
Here is the code as of last night:
int randomNumber = 1;
int userGuess = 1;
int countGuesses = 1;
int moreGuesse = 1;
moreGuesse++;
BOOL oneGuess = TRUE;
BOOL guessing = TRUE;
BOOL continueGuessing = TRUE;
BOOL keepPlaying = TRUE;
char yesNo = ' ';
while (keepPlaying)
{
randomNumber = (random()%101);
NSLog(@"The random Number to guess is: %i", randomNumber);
continueGuessing = TRUE;
while (continueGuessing)
{
NSLog(@"Pick a Number between 0 and 100.");
scanf ("%i", &userGuess);
fgetc(stdin);//remove CR/LF i.e extra character
if (userGuess == randomNumber)
{
continueGuessing = FALSE;
NSLog(@"Correct Number!");
}
//nested if statement
else if (userGuess > randomNumber)//an else if statement
{
//user guessed too high
NSLog(@"Your guess is too high");
}
else
{
//no reason to check if userGuess < randomNumber. It has to be
NSLog(@"Your guess is too low");
}
//refactored from our Alice app. This way we only have to code once.
NSLog(@"The user guessed %d", userGuess);
if (oneGuess != randomNumber)
{
NSLog(@"You have guessed %d time", countGuesses);
}
else if (guessing > randomNumber)
{
NSLog(@"You have guessed %d times", moreGuesse);
}
}
NSLog(@"Play Again? Y or N");
yesNo = fgetc(stdin);
if (yesNo == 'N')
{
keepPlaying = FALSE;
}
}
Any assistance would be very helpfull, if your going to be discouraging and tell me that coding is hard and I should not attempt it...back off I have a keyboard and I am not afraid to use it.....
The exercise requires me to insert a count of how many times the user guesses before they get the correct answer.
I get the one count, but for some reason I can get it to increment.
I have looked around for the answer but the ones that I have found, touch on subjects that the book has not touched upon.
Please if you can assist, it would be great.
Here is the code as of last night:
int randomNumber = 1;
int userGuess = 1;
int countGuesses = 1;
int moreGuesse = 1;
moreGuesse++;
BOOL oneGuess = TRUE;
BOOL guessing = TRUE;
BOOL continueGuessing = TRUE;
BOOL keepPlaying = TRUE;
char yesNo = ' ';
while (keepPlaying)
{
randomNumber = (random()%101);
NSLog(@"The random Number to guess is: %i", randomNumber);
continueGuessing = TRUE;
while (continueGuessing)
{
NSLog(@"Pick a Number between 0 and 100.");
scanf ("%i", &userGuess);
fgetc(stdin);//remove CR/LF i.e extra character
if (userGuess == randomNumber)
{
continueGuessing = FALSE;
NSLog(@"Correct Number!");
}
//nested if statement
else if (userGuess > randomNumber)//an else if statement
{
//user guessed too high
NSLog(@"Your guess is too high");
}
else
{
//no reason to check if userGuess < randomNumber. It has to be
NSLog(@"Your guess is too low");
}
//refactored from our Alice app. This way we only have to code once.
NSLog(@"The user guessed %d", userGuess);
if (oneGuess != randomNumber)
{
NSLog(@"You have guessed %d time", countGuesses);
}
else if (guessing > randomNumber)
{
NSLog(@"You have guessed %d times", moreGuesse);
}
}
NSLog(@"Play Again? Y or N");
yesNo = fgetc(stdin);
if (yesNo == 'N')
{
keepPlaying = FALSE;
}
}
Any assistance would be very helpfull, if your going to be discouraging and tell me that coding is hard and I should not attempt it...back off I have a keyboard and I am not afraid to use it.....