Help please!
How do I change this so I input the letters instead of numbers?
I'm confused. I want to make it so I can enter "R" instead of "0" etc. Also, I don't know where to put an if-break for the user to enter "Q" or "q"...

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;


int main()
{
    srand(time(0));

    int R = 0; //rock
    int P = 1; //paper
    int S = 2; //scissors
    int choice;

    int compchoice = (rand()%2) + 1;
    cout << "Choose: [Rock,Paper,Scissors,Quit]: ";
    cout << "R for rock, P for paper, S for scissors, or Q for quit\n";
    cin >> choice;
    
    if (choice == R) 
    {
              if (compchoice == R)
              cout << "It's a tie!\n\n\n\n";
              else if (compchoice == P)
              cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
              else if (compchoice == S)
              cout << "Rock beats scissors! You win!\n\n\n\n";
    }
    
    if (choice == P)
    {
               if (compchoice == R)
               cout << "It's a tie!\n\n\n\n";
               else if (compchoice == P)
               cout << "Paper beats rock! You win!\n\n\n\n";
               else if (compchoice == S)
               cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
   }
   
   if (choice == S)
   {
              if (compchoice == R)
              cout << "It's a tie!\n\n\n\n";
              else if (compchoice == P)
              cout << "Scissors beat paper! You win!\n\n\n\n";
              else if (compchoice == S)
              cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
   }

    return 0;
}

you could use the string header or start messing with character arrays

string rock = "R"

also with the if statement you dont need to use a nested if just do this
if (choice == R && compchoice== R)
{
so and so
}

If you just want to use a letter, use the variable "char." Also remeber that characters are enclosed in single qoutes( ' ), and strings in double quotes (" "). You also need to include <string> for strings if you aren't using Devc++ as a compiler(which includes string under iostream). Also, I suggest using a single switch statement with three cases over if statements.

#include <iostream>
#include <string>

using namespace std;

int main() {

char character;
string example;

character = 'a';         //you can use characters just like integer statements in your if statements as long as you are comparing characters to characters(just like how you wouldn't compare a sentence to a letter or a number to a letter)
string example = "this is how you make a string";

cout<<example<<endl<<character;

return 0;

output:
this is how you make a strong
a

This article has been dead for over six months. Start a new discussion instead.