Its me again. I'm stuck once again with another program that I don't fully understand, this "Prof." sucks! But of course I'm not asking anyone to write a program for me. The assignment is posted below...
Loops and Random Numbers
Write a program to play a game of scramble. The scrambled word is displayed and the user should have 3 tries to guess the correct word. For example, the word RAMPRGIONMG and user should guess the correct word. When the user guesses 3 times and does not get the correct word, you should display the correct word. For example, PROGRAMMING. If the user guesses correctly within 3 tries, congratulate the user. At the end of the first game, ask the user if they would like to play the game again. If they do, display another word and repeat the above steps. Otherwise quit the game.
Use at least 2 different types of loops.
You should make available at least 3 words.
Hint:
1. IF the number of times is divisible by 1, then set the correct word to the first word.
2. IF the number of times is divisible by 2, then set the correct word to the second word.
3. IF the number of times is divisible by 3, then set the correct word to the third word.
4. Copy the correct word to a new string object.
5. Use a loop and random numbers to scramble the correct word in the new string object.
6. Display the scrambled word.
7. Give the user 3 tries to guess the correct word.
8. If the user guesses correct within 3 tries, congratulate the user.
9. Otherwise after 3 tries, display the correct word.
10. Ask the user if they would like to guess another word.
11. If they do, return to the start of the loop.
12. Otherwise, quit the program.
First of all, he has not mentioned or went over random numbers, nor do I understand the first 3 "hints." I keep getting errors because I have not initialized my characters, I don't want to initialize them! Is there a way around this? I have no idea what this means >#include <cstdlib>, he told us to put it in our program, so I did. Sorry my posts are sooo dang long. Anyways, here is what I have so far
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
void main()
{
char exitCharacter = 'c';
string a("money");
string b("yeonm");
string c("shopping");
string d("pgiopshn");
string e("school");
string f("hocols");
cout << "Welcome to Word Guess! The fun game where you try to unscramble the word." << endl;
cout << "Good luck, and have fun." << endl;
cout << "Here is the first word:" << endl;
cout << "yeonm" << endl;
if (yeonm == money)
cout << "Great!" << endl;
else
cout << "Better luck next time." << endl;
cout << "Here is the second word:" << endl;
cout << "pgiopshn" << endl;
if (pgiopshn == shopping)
cout << "Great!" << endl;
else
cout << "Better luck next time." << endl;
cout << "Here is the third and final word:"<< endl;
cout << "hocols" << endl;
if (hocols == school)
cout << "Good job! Would you like to play again?" << endl;
else
cout << "Better luck next time." << endl;
while (exitCharacter =='c' || exitCharacter == 'C' ) {
cout << "Hit c to exit, any other key will terminate the program: " << endl;
}
}
Thanks for any and all help!
Kristina