- Joined
- Mar 21, 2009
hey guys i have to write this C++program i am a beginner but i am very confuse i have to
Write a program that asks the user to enter his/her full name. The full name (including spaces) must be stored in a single string. Declare the string with a maximum of 40 characters.
- Calculate the number of characters (L) in the string holding the full name and generate a random number (target) between 1 and L (remember to seed the random number generator with the current CPU time).
- Send these numbers (L and target) as input parameters to a function called Guess.
- Inside the function Guess ask the user to guess the target number. If the user enters a number out of the range (smaller than 1 or larger than L), notify so and ask for the number again.
- Once the user enters a valid number (within the range), compare it to the target number and return a value of 0 to the main function if the user guessed incorrectly or return a value of 1 to the main function if the user guessed correctly.
- Back in the main function, use the returned value from the function Guess to notify the user whether the guess was correct or incorrect.
- Give the user three (3) chances to guess the target number
this i was i got so far
#include <iostream>
#include <string>
using namespace std;
int main()
{
int userName;
int userGuess;
cout <<"Enter you full name: ";
cin >> userName;
cout <<"Enter and guess between 1 and 15:"<<userGuess<<"\n";
cin >>userGuess;
if ((userGuess < 1) || (userGuess > 15))
{
cout << "Your guess is out of the range, try again...\n\n";
cout << "Another chance...\n";
}
}
Write a program that asks the user to enter his/her full name. The full name (including spaces) must be stored in a single string. Declare the string with a maximum of 40 characters.
- Calculate the number of characters (L) in the string holding the full name and generate a random number (target) between 1 and L (remember to seed the random number generator with the current CPU time).
- Send these numbers (L and target) as input parameters to a function called Guess.
- Inside the function Guess ask the user to guess the target number. If the user enters a number out of the range (smaller than 1 or larger than L), notify so and ask for the number again.
- Once the user enters a valid number (within the range), compare it to the target number and return a value of 0 to the main function if the user guessed incorrectly or return a value of 1 to the main function if the user guessed correctly.
- Back in the main function, use the returned value from the function Guess to notify the user whether the guess was correct or incorrect.
- Give the user three (3) chances to guess the target number
this i was i got so far
#include <iostream>
#include <string>
using namespace std;
int main()
{
int userName;
int userGuess;
cout <<"Enter you full name: ";
cin >> userName;
cout <<"Enter and guess between 1 and 15:"<<userGuess<<"\n";
cin >>userGuess;
if ((userGuess < 1) || (userGuess > 15))
{
cout << "Your guess is out of the range, try again...\n\n";
cout << "Another chance...\n";
}
}