No Output

So I was writing a rock paper scissors game for fun/practice and I came across an issue that I can't figure out. I'm using CodeLite 6.1.1 with the mingw compiler, and when I run the code I only get "Press any key to continue." returned. However, when I run the code on CodeBlocks it works. I've narrowed down the issue to the srand() time() and rand() function. So somehow my cstdlib and ctime headers are faiing. I've already reinstalled codelite and even tried the update out. It only works on CodeBlocks. Any ideas 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

void playGame(void);
void setResult(int);
int getResult();
void clearScreen(void);

int result;

int main()
{
	string name;
	int winCount = 0, loseCount = 0, tieCount = 0, player;

	cout << "Let's play competitive Rock, Paper, Scissors." << endl;
	cout << "Type in your name to begin: ";
	cin >> name;

	cout << endl << name << ", welcome to Rock, Paper, Slayer.\n";
	cout << "You will be competing against other computer generated players who will be \n";
	cout << "trying to out-think your next move with a super-duper unpredictable algorithm. \n";
	cout << "\tBest 2 out of 3 wins defeats the player.\n\tWin one round to continue to the next. \n";
	cout << "\tThere are 10 players to compete against. A tie will restart the round.\n";
	cout << "\tThis is a game of luck. Have fun!\n\n";

	for(player=1; player<=10; player++){
		cout << "\t\t\t**** PLAYER " << player << " ****\n";
		cout << "\t\t\tWins: " << winCount << "\tLosses: " << loseCount << endl << endl;
		playGame();
		if(getResult() < 3){
			if(getResult() == 0){
				cout << "You lost that round!";
				loseCount++;
			} else if(getResult() == 1) {
				cout << "You won that round!";
				winCount++;
			} else {
				cout << "It was a tie!";
				tieCount++;
			}
		} else {
			break;
		}
		clearScreen();
	}

	if(getResult() == 3){
		cout << "\nYou have quit the game.\n\n";
	}

	cout << "You competed against " << player - 1 << " player(s)." << endl;
	cout << "You won " << winCount << " time(s).\n";
	cout << "You lost " << loseCount << " time(s).\n";
	if(tieCount > 0){
		cout << "You tied " << tieCount << " time(s).\n";
	}
	return 0;
}

void clearScreen(){
	cout << string(100,'\n');
	//system("cls");
}

void setResult(int res){
	result = res;
}

int getResult(){
	return result;
}

void playGame(){
	char menu;
	string item;
	int userChoice, compChoice, win_Count = 0, lost_Count = 0, ties = 0;

	for(int i=1; i<=3;i++){
		cout << "\t\tPlayer Wins: " << win_Count << "\tTies: " << ties << "\tComputer Wins: " << lost_Count << endl;
		cout << "**** ROUND " << i << " ****" << endl;
		cout << "\tRock (r)\n\tPaper (p)\n\tScissors (s)\n\tQuit (q)\nEnter a character to begin: ";
		cin >> menu;

		switch(menu){
		case 'R':
		case 'r':
			userChoice = 1;
			break;
		case 'P':
		case 'p':
			userChoice = 2;
			break;
		case 'S':
		case 's':
			userChoice = 3;
			break;
		case 'Q':
		case 'q':
			setResult(3);
			userChoice = 4;
			break;
		default:
			cout << "\n*** Invalid Character! ***\n";
			userChoice = 5;
			break;
		}

		int seed = userChoice * time(NULL) - 50;
		srand(seed);

		compChoice = rand()%(3) + 1;

		if(compChoice == 1){
			item = "rock";
		} else if (compChoice == 2){
			item = "paper";
		} else {
			item = "scissors";
		}

		if(userChoice == 4){
			return;
		}

		if(userChoice != compChoice && userChoice != 5){
			if((userChoice == 1 && compChoice == 2) || (userChoice == 2 && compChoice == 3) || (userChoice == 3 && compChoice == 1)){
				cout << "\nYou lose! I picked " << item << "!\n";
				lost_Count++;
				cout << endl;
			} else {
				cout << "\nYou win! I picked " << item << ".\n";
				win_Count++;
				cout << endl;
			}
		} else if(userChoice == 5) {
			i--;
			cout << endl;
		} else {
			cout << "\nIt's a tie! I also picked " << item << "!\n";
			ties++;
			i--;
			cout << endl;
		}
	}
	if(win_Count > lost_Count){
		setResult(1);
		//cout << "You won against this player.\n\n";
	} else if (win_Count == lost_Count){
		setResult(2);
		//cout << "You tied against this player.\n\n";
	}else{
		setResult(0);
		//cout << "You lost against this player.\n\n";
	}
}
It is working perfectly fine for me on Visual Studio 2013. There is nothing wrong in the code, but maybe in CodeLite 6.1.1 or the compiler they are using they do something a bit differently.
Topic archived. No new replies allowed.