Now this whole exercise seems too difficult for me |
You should resist the urge to try to program the entire thing at once. This code isn't close to functional. Start from this point:
1 2 3 4
|
int main()
{
return 0;
}
|
Start modifying it by asking for input from the user, and proving that you've stored it correctly.
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
#include <string>
int main()
{
std::string userInput;
std::cout << "Enter \"rock\", \"paper\", or \"scissors\": ";
std::cin >> userInput;
std::cout << "You entered " << userInput << std::endl;
return 0;
}
|
Now that you know userInput holds the correct information, you could then try to validate it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <string>
int main()
{
std::string userInput;
std::cout << "Enter \"rock\", \"paper\", or \"scissors\": ";
std::cin >> userInput;
bool validInput;
if (s == "rock" || s == "paper" || s == "scissors")
{
validInput = true;
}
else
{
validInput = false;
}
if (validInput)
{
std::cout << "Good input";
}
else
{
std::cout << "Bad input";
}
return 0;
}
|
Make sure each step along the way works before moving to the next one. It helps to plan out a series of small steps that lead to solving your problem.
1. get input
2. validate input
3. generate computer move (doesn't have to be random, make it always choose paper at first)
4. compare user input and computer move to determine a winner
5. move the code to generate a computer move into its own function
6. make the computer play random
You may think of more discrete steps along the way, but if you try to do everything at once you will get lost quickly.