This is getting to make-or-break for me. We've been given a list of ten questions for our assignment. I've done three, but the others are breaking my heart. I can't get anywhere with any of them. I'm plugging away but I'm a hair's breath from dropping out of the course because I'm just not capable of this.
This is a program which is supposed to ask for a user to guess a number between 1 and 10, and to keep reasking the user to guess if the guess is outside that range. I've come up with this but to be honest its probably complete BS and would never work if I kept at it till Xmas.
Am I even remotely close?
Also, is there any online I can search for examples of code using while and if. Perhaps if I could find something it would make more sense to me. I don't want to keep hounding you guys with questions.
#include<stdio.h>#define ANSWER 4 /*Define constant of ANSWER*/
printf("This is a number between 1 and 10. Enter your guess:"); /*Read guess from the keyboard*/
scanf("%d" ,&guess); /*Read user input*/
( guess >= 1 && guess <= 10 );
printf("Please enter another guess within the correct range:\n");
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 */