-
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
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand(time(NULL));
int randomnumber = 1+(rand()%1000);
int guess = 0;
printf("\nI have a number between 1 and 1000.");
printf("\nCan you guess my number?");
do
{
printf("\nPlease type your first guess between 1 and 1000: \n");
scanf("%d", &guess);
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)");
system("PAUSE");
return 0;
}
I need to finish the second part of it urgently
-
Split into its own thread from this thread.
-
hints:
rand() returns a random integer.
% is modulo operator, more or less.
Note that rand()%100 gives an integer between 0-99 inclusive.
Similar Threads
-
By QuinnMal in forum Java
Replies: 0
Last Post: 07-05-2007, 11:12 AM
-
By vbjunkie1 in forum C++
Replies: 5
Last Post: 03-24-2007, 03:13 AM
-
Replies: 18
Last Post: 12-13-2006, 03:49 PM
-
By cmvw in forum VB Classic
Replies: 7
Last Post: 06-28-2006, 10:04 AM
-
Replies: 0
Last Post: 10-16-2005, 01:22 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|