Hello Sunny2612,
While working to get the program to compile one of the errors I received was for the use of an uninitialized variable, "comp". It is good practice to initialize all variables when they are defined. Most variables like "int"s, "double"s, "char" should be initialized when defined. The use of a set of empty {}s after the variable name is all that is need. "std::string", "std::vector" and a couple of others are the exceptions.
The use of "goto" is also bad programming. This can be replaced with a do/while loop like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
do
{
CLS;
std::cout << "Rock/Paper/scissors is a simple game. The rules are: \n Rock beats scissors. \n Scissors beats Paper. \n Paper beats rock.\n";
std::cout << "Game Choices.\n\n";
std::cout << "1. Rock\n";
std::cout << "2. Paper\n";
std::cout << "3. Scissors\n";
std::cout << "4. Quit, exits the game.\n";
std::cout << "\nPlease enter your choice : ";
std::cin >> choice;
select(choice);
if (choice != 1 && choice != 2 && choice != 3 && choice != 4)
{
std::cout << "\n Invalid choice. Try again.";
std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
}
} while (choice != 1 && choice != 2 && choice != 3 && choice != 4);
|
The "CLS;" is my replacement for your "clrscr()".
Line 19. I used to pause long enough to read the message. The whole number in ()s is the amount of seconds to pause.
The function "cselect()" looks OK, but you get the computers pick and then loose it when the function ends. This function needs to return an int and return comp just before the closing brace of the function.
Back in main the if statements that start t line 101 in your code do not cover all possibilities. I am thinking this should be if/else if statements and you mab be able to do everything with one set of if/else if statements.
I am not worried about it now, but eventually most of what is in main would need to be inside a while loop with the option to continue at the end of the while loop. This way the game would continue until you type "N" to end.
Hope that helps,
Andy