Random Number Selection For Game
I WAS GIVEN THIS ASSIGNMENT BUT IT IS NOT YET COMPLETE AND i NEED TO COMPLETE IE URGENTLY
Write an application that plays "Guess the number" as follows: Your program chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The program then types:
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
The player then types a first guess. The program responds with one of the following:
1. Excellent! You guessed the number on the n th try!
would you like to play again (y/n)?
2. Too low. Try again.
3. Too high. Try again.
If the player's guess is incorrect, your program should display "Too high. Try again" or "Too low. Try again." to help the player. The program then asks for the next guess. When the user enters the correct answer, display "Excellent, you guessed the number on the n th try!", and allow the user to choose whether to play again. Replace n with the number of tries user needed to guess the number right.
WRITE AT LEAST TWO SEPARATE FUNCTIONS IN YOUR PROGRAM! Besides the main function you can for example have a function, which returns a random integer in the range 1 to 1000.
I stopped here but I need to continue
int randomnumber = 1+(rand()%1000);
int guess = 0;
printf("\nI have a number between 1 and 1000.");
printf("\nCan you guess my number?");
printf("\nPlease type your first guess between 1 and 1000: \n");
if (guess < randomnumber) // If guess is < than the random number, display
printf("Your guess was too low\n\n");
if (guess > randomnumber) // If guess is > than the random number, display
printf("Your guess was too high\n\n");
} while (guess != randomnumber); // While guess is not equal to the random number
printf("\nCongratulations! You've guessed the number.\n");
printf("\nWould you like to play again (Y/N)");
I need to finish the second part of it urgently
Split into its own thread from this thread.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
rand() returns a random integer.
% is modulo operator, more or less.
Note that rand()%100 gives an integer between 0-99 inclusive.
By QuinnMal in forum Java
Last Post: 07-05-2007, 12:12 PM
By vbjunkie1 in forum C++
Last Post: 03-24-2007, 04:13 AM
Last Post: 12-13-2006, 03:49 PM
By cmvw in forum VB Classic
Last Post: 06-28-2006, 11:04 AM
Last Post: 10-16-2005, 02:22 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center