Click here to Skip to main content
15,915,328 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help my code goes straight to "Press any key to continue..." then it closes. I am fairly new to coding so excuse my stupedness, anyways yeah I tried adding return 0; everywhere and it still just doesn't work. PLEASE HELP!!!

C++
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>

using namespace std;

int rouletteGen();

int main()
{	
	//--------
	//| Idea |
	//--------
	//cout << box 1 << box 2 << endl;

	int wheel, a, b, c, time, cA, cB, cC;
	a = 0;
	b = 0;
	c = 0;
	time = 500;

	while (a > 1)
	{
		cC = rouletteGen();
		if (cC >= 0 && cC <= 15)
		{
			cC = 1;
		}
		else if (cC >= 16 && cC <= 30)
		{
			cC = 2;
		}
		else if (cC == 31)
		{
			cC = 0;
		}
		cout << "          _l_" << endl;
		cout << "          \l/" << endl;
		cout << "_______ _______ _______" << endl;
		cout << "I     I I     I I    I" << endl;
		cout << "I  "<< " " <<"  I I  "<< " " <<"  I I  "<< cC<<"   I" << endl;
		cout << "I     I I     I I    I" << endl;
		cout << "_______ _______ _______" << endl;

		Sleep(250);
		c++;
		while (b > 1)
		{
			cB = cC;
			cC = rouletteGen();
			if (cC >= 0 && cC <= 15)
			{
				cC = 1;
			}
			else if (cC >= 16 && cC <= 30)
			{
				cC = 2;
			}
			else if (cC == 31)
			{
				cC = 0;
			}
			cout << "          _l_" << endl;
			cout << "          \l/" << endl;
			cout << "_______ _______ _______" << endl;
			cout << "I     I I     I I     I" << endl;
			cout << "I  " << " " << "  I I  " << cB << "  I I  " << cC << "   I" << endl;
			cout << "I     I I     I I     I" << endl;
			cout << "_______ _______ _______" << endl;

			cin.get();
			c++;
			Sleep(250);
			while (c >= 15)
			{
				cA = cB;
				cB = cC;
				cC = rouletteGen();
				if (cC >= 0 && cC <= 15)
				{
					cC = 1;
				}
				else if (cC >= 16 && cC <= 30)
				{
					cC = 2;
				}
				else if (cC == 31)
				{
					cC = 0;
				}
				cout << "          _l_" << endl;cout << "          \l/" << endl;
				cout << "_______ _______ _______" << endl;
				cout << "I     I I     I I     I" << endl;
				cout << "I  " << cA << "  I I  " << cB << "  I I  " << cC << "   I" << endl;
				cout << "I    I I     I I     I" << endl;
				cout << "_______ _______ _______" << endl;
				Sleep(time);
				time += 100;
				return 0;
			}
			return 0;
		}
		return 0;
	}
	return 0;
}

int rouletteGen()
{
	int dice;
	srand(time(NULL));
	dice = rand() % 31;

	dice = dice + 1;

	return dice;

}
Posted
Comments
Sergey Alexandrovich Kryukov 22-Jan-16 11:24am    
You already got two answers, but I think main advice should be: use the debugger.
—SA

C
a = 0;
 
while (a > 1)


At the point of the while loop a is 0, so will never be > 0 so your loop never executes and it goes right to return 0.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 22-Jan-16 11:23am    
5ed.
—SA
You have a while (a > 1) which evaluates to false right from the start because you set a = 0; at the beginning.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Jan-16 11:23am    
5ed.
—SA
Sascha Lefèvre 23-Jan-16 5:51am    
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900