Я беру курс C++ и выполняю задание, включающее перечисления и случайный выбор. Мой код кажется сломанным. Мое перечисление продолжает рассматриваться как int, а не char, и XCode продолжает давать мне ожидаемый идентификатор в строке с моим перечислением. Логика игры использует символы, а не целые числа. Как я могу это исправить?
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <random>
#include <time.h>
int main()
{
std::cout << "Let's play some Rock, Papers, and Scissors!\nEnter a choice to Start: R, P, or S!" << std::endl;
char pInput;
std::cin >> pInput;
srand( time(NULL) );
int cInput = rand() % 3; //Computer chooses number mapped to chars R, P, or S
enum class RockPaperScissors { 'R', 'S', 'P' };
if( pInput == 'R' && cInput == 'R' )
{
std::cout << "You tied with me!" << std::endl;
}
else if( pInput == 'R' && cInput == 'S' )
{
std::cout << "Drats! You win!" << std::endl;
}
else if( pInput == 'R' && cInput == 'P' )
{
std::cout << "Hah! Here comes the Hug of Death!" << std::endl;
}
else if( pInput == 'S' && cInput == 'S')
{
std::cout << "Looks like we tied!" << std::endl;
}
else if( pInput == 'S' && cInput == 'R')
{
std::cout << "Hah! I smashed you, so I win!" << std::endl;
}
else if( pInput == 'S' && cInput == 'P')
{
std::cout << "Drats! You win!" << std::endl;
}
else if( pInput == 'P' && cInput == 'P')
{
std::cout << "Drats! We tied!" << std::endl;
}
else if( pInput == 'P' && cInput == 'S')
{
std::cout << "Hah! I win, because I'm a scissor!" << std::endl;
}
else if( pInput == 'P' && cInput == 'R')
{
std::cout << "Drats! You gave me the Hug of Death!" << std::endl;
}
}