Hello, I'm VERY new to C and C++ and I am trying to write code for a college course. I'm not asking anyone to write the code, I just do not understand why my while loop is not working? The program seems to stop after saying the instructions.
int main(){
int tooLow = 0;
int tooHigh = 100;
int guess = 50;
int tries = 1;
char answer[20] = "'x'";
printf("Think of a number between 1-100. \n");
printf("I'm going to guess the number in 7 or less tries. \n");
printf("Tell me my guess is too high by typing H, tell me it's too low by typing L, or tell me it's correct with C. \n");
while (*answer != 'C');
printf("Is your number %d? Try #%d \n", guess, tries);
scanf("%s", answer);
tries++;
if (*answer == 'H');
tooHigh = guess;
guess = rand()%(tooLow-tooHigh);
if (*answer == 'L');
tooLow == guess;
guess = rand()%(tooLow-tooHigh);
}//end main
int main() {
int tooLow = 0;
int tooHigh = 100;
int guess = 50;
int tries = 1;
char answer[20] = "'x'";
printf("Think of a number between 1-100. \n");
printf("I'm going to guess the number in 7 or less tries. \n");
printf("Tell me my guess is too high by typing H, tell me it's too low by ""typing L, or tell me it's correct with C. \n");
while(*answer != 'C')
; //NOTE
printf("Is your number %d? Try #%d \n", guess, tries);
scanf("%s", answer);
tries++;
if(*answer == 'H')
; //NOTE
tooHigh = guess;
guess = rand() % (tooLow - tooHigh);
if(*answer == 'L')
; //NOTE
tooLow == guess;
guess = rand() % (tooLow - tooHigh);
} // end main
you've got semicolons as the body of the while and the ifs.
If you want several statements, then enclose them with {}
int main() {
int tooLow = 0;
int tooHigh = 100;
int guess = 50;
int tries = 1;
char answer[20] = "'x'";
printf("Think of a number between 1-100. \n");
printf("I'm going to guess the number in 7 or less tries. \n");
printf(
"Tell me my guess is too high by typing H, tell me it's too low by ""typing L, or tell me it's correct with C. \n");
while(*answer != 'C') { //NOTE
printf("Is your number %d? Try #%d \n", guess, tries);
scanf("%s", answer);
tries++;
if(*answer == 'H'){ //Open block
tooHigh = guess;
guess = rand() % (tooLow - tooHigh);
} //Closing block
if(*answer == 'L'){
tooLow == guess;
guess = rand() % (tooLow - tooHigh);
}
} //end while
} // end main