Switch statement problem

On line 34 I am getting the error "switch quantity is not an integer. Could someone explain why?

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
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;
int getUserChoice()
{
    int choice;
    do
    {

    cout <<"1. Rock\n";
    cout <<"2. Paper\n";
    cout <<"3. Scissors\n";
    cout <<"4. Lizard\n";
    cout <<"5. Spock\n";
    cout <<"Enter a choice: ";
    cin >> choice;
    cin.clear();
    cin.ignore();
    }while(cin.fail() || (choice < 1) || (choice > 5));
    return choice;
}
int getComputerChoice()
{
    srand(time(0));
    int computerChoice;
    computerChoice = (rand() % 5) + 1;
    return computerChoice;
}
int determineWinner();
int displayChoice()
{
    switch(getUserChoice)
    {
    case 1 : cout << "You chose Rock";
    break;
    case 2 : cout << "You chose Paper";
    break;
    case 3 : cout << "You chose Scissors";
    break;
    case 4 : cout << "You chose Lizard";
    break;
    case 5 : cout << "You chose Spock";
    break;
    }
}

int main()
{
    getComputerChoice();
    getUserChoice();
Look at your line 34. What is "getUserChoice" there?
I see now. I wasn't storing it in anything. Thank you.
Last edited on
closed account (49iURXSz)
You don't necessarily need to store it; a function will return an integer value. But you've told the compiler in that statement there's a variable getUserChoice. Just add your parenthesis:

34: switch(getUserChoice())
Topic archived. No new replies allowed.