Rock Paper Scissors program

Hello everyone. I'm pretty new to C++ and am having trouble with this program. It does everything I need it to, except I would like it to display the computers choice as a word (rock, paper...) instead of the number. Is there any way to do this without using a bunch of if statements?

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
#define  over1  "\t"
#define  over2  "\t\t"
#define  over3  "\t\t\t"
#define  over4  "\t\t\t\t"
#define  over5  "\t\t\t\t\t"
#define  down4  "\n\n\n\n"
#define  down5  "\n\n\n\n\n"
#define  down8  "\n\n\n\n\n\n\n\n"
#define  down10 "\n\n\n\n\n\n\n\n\n\n"

  
using namespace std;

void clown()  ;
void welcome() ;

using namespace std;

int main(int argc, char *argv[])
{
    //function call
    //clown();
    //welcome();
    
    system("CLS");
   
    int option, comp, win, loss, tie;
    int rock = 1, paper = 2, scissors = 3, exit = 4;
    unsigned int seed = time(NULL);
    string rock_, paper_, scissors_;
    
    win = loss = tie = 0;
    
    srand(seed);
    
    
    do
    {
        comp = 1 + rand() % 3;

        system("CLS");
        cout << down4;
        cout << over4 << "Rock, Paper, Scissors!" << endl
             << over4 << "----------------------" << endl
             << over4 << "1. Rock" << endl
             << over4 << "2. Paper" << endl
             << over4 << "3. Scissors" << endl
             << over4 << "4. Exit" << endl
             
             << over4 << "option: " ;
       cin >> option;
       cout << endl << endl;
       
       
        
        //combines nested structure into more effecient lines
        if ((option==rock && comp==scissors ) || (option==paper && comp==rock) || (option==scissors && comp==paper))
        {
            cout << over4 << "The PC chose: " << comp << endl;
            cout << over4 << "You win!";
            win++;             
        }
        else if ((option==3 && comp==1 ) || (option==1 && comp==2) || (option==2 && comp==3))
        {
            cout << over4 << "The PC chose: " << comp << endl;
            cout << over4 << "You lose!";
            loss++;     
        }
        else if ((option==1 && comp==1 ) || (option==2 && comp==2) || (option==3 && comp==3))
        {
            cout << over4 << "The PC chose: " << comp << endl;
            cout << over4 << "It's a tie!";     
            tie++;
        }
        
        
        else if (option == exit)
        {
            cout << over4 << "      Exit\n" << endl;
            cout << over4 << " Wins \t Losses\t Ties" << endl
                 << over4 << "-------\t-------\t--------" << endl
                 << over4 << setw(4) << win
                 << over1 << " " << setw(4) << loss
                 << over1 << setw(4) << tie;
        }
        
        else if (option != rock, paper, scissors, exit)
        {
            cout << over3 << "User choice not valid. Please try again." << endl;
        }
        
        else
        {
            
        }
        
        cout << down5;
        system("PAUSE");
  
    } while (option != exit);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Write a function to do it for you.
1
2
3
4
5
6
7
8
9
10
std::string getChoiceString(int rpsNum)
{
    switch(rpsNum)
    {
    case 1: return "rock";
    case 2: return "paper";
    case 3: return "scissors";
    default: return "";
    }
}

Then call the function when printing instead of using the number.
cout << over4 << "The PC chose: " << getChoiceString(comp) << endl;
Topic archived. No new replies allowed.