After much effort, I've gotten to here. This tells a user to re-guess if outside range, but does not react to a number within the correct range, nor the correct number.
I know its probably full of things that could be tidier, but we're having severe problems with our course. Most of the students are feeling like we're sinking and we're trying to work out ways to rectify.
Please could someone help, in the simplest terms possible because my brain is toast at this stage, how to finally finish this off?
Code:
#include <stdio.h> #include <stdlib.h>
#include <math.h>
#include <conio.h>
#define ANSWER 4 /*Define constant of ANSWER*/
int main(void)
{
int guess;
printf("Enter your guess. Number is between 1 and 10:");
scanf("%d", &guess);
while( guess >= 1 || guess <= 10)
{
if(guess > 10)
{
printf("Too high, Guess again:");
scanf("%d", &guess);
}
if(guess < 1)
{
printf("Too low, guess again:");
scanf("%d", &guess);
}
}
while( guess <= 1 || guess >= 10)
{
if ( guess == ANSWER ) /*If clause to define if user's guess is correct*/
{
printf("You guessed correctly, the answer was 4."); /*If guess is correct this message will show*/
}
if (guess < ANSWER) /*If clause to define if user's guess is smaller than ANSWER*/
{
printf("You guessed incorrectly, the answer is greater."); /*If guess is smaller this message will show.*/
}
if (guess > ANSWER) /*If clause to to define if user's guess is greater than ANSWER*/
{
printf("You guessed incorrectly, the answer is smaller."); /*If guess is smaller then this message will show */
}
}
return 0;
}