First post here, hopefully more to come. Anyway, I'm in an intro to C programming course and about in my fourth week in. So far, we've gone over printf/scanf functions, for/while loops, if statements and stuff like that.
Anyway, my teacher's powerpoint slides don't match the ones he had in class yet so I'm having a hard time with our the homework assignment. It's a number guessing program. What we have to do is get two user selected numbers, a lower number and higher number of any range. Then the program has to check if the first number is actually lower than the second number. If not, it tells the user to start over. After that, the computer randomly chooses a number between the lower and higher number (range). The user than has to guess the number. Finally, it has to end when the number guessed is correct and then output all the numbers with the correct number showing "correct" next to it. The program should ask the user if he/she wants to play again.
I am willing to learn, so here is the code I have now. I know there are syntax errors, but I was working on getting the main skeleton down (probably a bad habit). Can someone help push me in the right direction. I have a feeling I want to utilize a while loop and I know I need a sentinel in there somewhere for the last part. Keep in mind, it is pretty incomplete, but how far off am I? I wanted to check now so debugging will be easier, hope that made sense. Thanks in advance.
EDIT: so, to summarize: Is my first boolean statement fine with rand being set to the range between 1 and 2? If someone can point out how to make it within a while statement ended with a sentinel, I think I'm almost there. argh, I'm having more trouble on this assignment than my last calculus one.Code:#include <stdio.h> #include <time.h> #include <stdlib.h> int main() int seed; int counter; int number_1; int number_2; int my_random; int guess; seed=time(NULL); srand(seed); { printf("I will think of a number between two numbers of your choice. \n"); printf("What is the lower number?"); scanf("%d", &number_1); printf("What is the higher number?"); scanf("%d", &number_2); while(number_1>=number_2) { printf("The first number must be lower than the second. Please try again. \n"); } else(number_1<=number_2) { printf("I have figured out my number. Start guessing by entering a number."); my_random==(rand()>number_1<number_2; scanf("%d", &guess); } if(guess==my_random) { printf("You are correct!"); } else(guess!=my_random) { printf("Wrong! Try again."); } printf("Would you like to play again?") }