First, thank you for even thinking of helping me. I am a n00b at C and trying to learn every bit I can. I am seeking help so I can understand for future projects, not just an answerAlso excuse my poor English.
I have a lot written in the program so far. I am able to loop the code, allow user to guess number and it seems to work. My questions are 1. How can I store how many guesses they guessed? I know I would store it in a variable and display it at some point, just not sure how to save it. 2. How can I end the loop when the user guesses the correct answer? My code is below. Again thank you for any help.
Code:#include<stdlib.h> #include<stdio.h> int main(void) { int x = 10; int i = 0; int target, guess; /*create a random number*/ //create random function srand(time(NULL));//this creates new number based on time which changes every second :) target = rand() % 99; //create a random number using the rand() function, from 0 -99 / do{ //increase the loop until it meets the x variable i++; //allow user to input a number for guess scanf("%d", &guess); if (guess == target) { printf("You win! \n\n"); } else if (guess > target) { printf("You are too high. Guess a number:\n\n"); } else if (guess < target) { printf("You are too low. Guess a number:\n\n"); } }while(i < x); printf("You lose, the number was %d \n\n", target); printf("Enter any key to exit..."); getchar(); getchar(); return 0; }



LinkBack URL
About LinkBacks
Also excuse my poor English.



