Update to previous, new issue.

So i rewrote my rock, paper, scissors, lizard, spock game. It now actually loads the console and runs good until the player enters a choice. When the player chooses it goes to "playerName chose ####" press any key to continue... and closes out. What tips would you give to help me out? Here's the code:
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 #include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

void compFunc();
int computerChoice = 0;
string playerName;
int userChoice = 0;

int main(void) {
	cout << "What is your name? ";
	getline (cin, playerName);
	cout << "Hello, " << playerName<< ", let's play a game! \n";
	cout << "Do you choose rock, paper, scissors, lizard or Spock?";
	cout << "\n [1] Rock";
	cout << "\n [2] Paper";
	cout << "\n [3] Scissors";
	cout << "\n [4] Lizard";
	cout << "\n [5] Spock\n";
	cin >> userChoice;
		if (userChoice == 1) {
		cout << "You chose Rock ";
	}
	else if (userChoice == 2) {
		cout << "You chose Paper ";
	}
	else if (userChoice == 3) {
		cout << "You chose Scissors ";
	}
	else if (userChoice == 4) {
		cout << "You chose Lizard ";
	}
	else if (userChoice == 5) {
		cout << "You chose Spock ";
	}
	compFunc;
	if (computerChoice == 1) {
		cout << "I chose Rock ";
	}
	else if (computerChoice == 2) {
		cout << "I chose Paper ";
	}
	else if (computerChoice == 3) {
		cout << "I chose Scissors ";
	}
	else if (computerChoice == 4) {
		cout << "I chose Lizard ";
	}
	else if (computerChoice == 5) {
		cout << "I chose Spock ";
	}
	if (computerChoice == userChoice) {
		cout << "It's a draw ";
	}
	else if (computerChoice == 1) {
		if (userChoice == 3) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 4) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 5) {
			cout << playerName << " wins, congrats! ";
		}
		else if (userChoice == 2) {
			cout << playerName << " wins, congrats! ";
		}
	}
	else if (computerChoice == 2) {
		if (userChoice == 1) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 5) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 3) {
			cout << playerName << " wins, congrats! ";;
		}
		else if (userChoice == 4) {
			cout << playerName << " wins, congrats! ";
		}
	}
	else if (computerChoice == 3) {
		if (userChoice == 2) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 4) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 1) {
			cout << playerName << " wins, congrats! ";
		}
		else if (userChoice == 5) {
			cout << playerName << " wins, congrats! ";
		}
	}
	else if (computerChoice == 4) {
		if (userChoice == 2) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 5) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 1) {
			cout << playerName << " wins, congrats! ";
		}
		else if (userChoice == 3) {
			cout << playerName << " wins, congrats! ";
		}
	}
	else if (computerChoice == 5) {
		if (userChoice == 1) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 3) {
			cout << "I win, better luck next time. ";
		}
		else if (userChoice == 2) {
			cout << playerName << " wins, congrats! ";
		}
		else if (userChoice == 4) {
			cout << playerName << " wins, congrats! ";
		}
	}
	system("pause");

	return 0;
}

void compFunc() {
	computerChoice = rand() % 5 + 1;
/*computer choices: 1 = rock, 2 = paper, 3 = scissors, 4 = lizard, 5 = spock */
}


I was also thinking I should put a new function for the comparison part for example void compareAns(); but I'm not sure if that would just over complicate it when it may run fine as is.
I'm not going to read through all that- not to be rude. You should learn to use switch statements, have a look at this link:
http://www.cplusplus.com/doc/tutorial/control/

For example,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if (userChoice == 1) {
		cout << "You chose Rock ";
	}
	else if (userChoice == 2) {
		cout << "You chose Paper ";
	}
	else if (userChoice == 3) {
		cout << "You chose Scissors ";
	}
	else if (userChoice == 4) {
		cout << "You chose Lizard ";
	}
	else if (userChoice == 5) {
		cout << "You chose Spock ";
	}


should be written such as:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    switch(userChoice){
    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;
    }


Topic archived. No new replies allowed.