Sign in to follow this  
NUCLEAR RABBIT

Noob in Distress!

Recommended Posts

Hello, 1st Problem: I have created my second game (1st was tic tac toe) and I seem to have a minor, but big problem with one aspect of the game. The game I created was a 'Craps' Clone. Those of you that dont know what that is, its a dice game. The problem Im having is that in the game, it keeps track of your rolls (ex: roll #1 roll #5 ..etc.). What seems to be happeneing is that it skips numbers, first its on the first roll, then it goes to the 3rd roll, and so on. 2nd Problem: In addition, there is one more small problem, i get the error message: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data. ( Coded in C++ with Visual C++ Express 8 ) Whole Game Code: ( Updated )
/*******************************************************************************
**                                                                            **
**                                Crap Mania!                                 **
**                                                                            **
**                              By: Brandon Wall                              **
**                                                                            **
**                                  6/04/06                                   **
**                                                                            **
*******************************************************************************/

#include "stdafx.h"
#include <iostream>
#include <ctime>

using namespace std;

void playGame();
void quitGame();
void lostGame();
void winGame();

int main(int argc, char* argv[])
{
	bool start = false;
	char menuSelection;

	srand((unsigned int)time(0));

	while(!start)
	{
		system("CLS");
		system("COLOR 2f");
		cout << "\n\n\n\n\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$     Welcome To Crap Mania!     $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$  ----------------------------  $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$  (G) Gamble      (C) Crap Out  $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$  ----------------------------  $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$   Rules:                       $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$   -Roll 7 or 11 on the first   $$\n"
			 << "\t\t\t$$    Roll to win.                $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$   -Roll 2, 3, or 12 on the     $$\n"
			 << "\t\t\t$$    first Roll and you lose.    $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$   -Roll the same point value   $$\n"
			 << "\t\t\t$$    as your first roll to win   $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$  ----------------------------  $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$  Game Created By Brandon Wall  $$\n"
			 << "\t\t\t$$                                $$\n"
			 << "\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n"
			 << "\t\t\t\t  Your Selection: ";
		cin >> menuSelection;

		if(menuSelection == 'g')
		{
			playGame();
			start = true;
		}

		if(menuSelection == 'c')
		{
			quitGame();
		    start = true;
		}

		if(menuSelection != 'g' && menuSelection != 'c')
		{
			system("cls");
		    start = false;
		}
	}

	return 0;
}

/**********************
**                   **
**     PLAY GAME     **
**                   **
**********************/

void playGame()
{

// Rolls
int oR, oR2 = 0;
int r1, r2 = 0;
int counter = 0;

bool game = false;

  while(!game)
  {
	system("CLS");
    
	r1 = rand() % 6;
	r2 = rand() % 6;

	counter++;
	bool roll = false;

	//while(!roll)
	//{
	if( r1 == 1 && r2 == 1 )
	{
		cout << "|=================|  |=================|\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|        O        |  |        O        |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|=================|  |=================|\n\n"
			 << "You Rolled Snake Eyes!\n\n";
		
		if(counter == 1)
		{
			cout << "You Lose!\n\n";
			system("PAUSE");
			lostGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 1 && r2 == 2 || r1 == 2 && r2 == 1 )
	{
		cout << "|=================|  |=================|\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |              O  |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|        O        |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |  O              |\n"
			 << "|                 |  |                 |\n"
			 << "|=================|  |=================|\n\n"
			 << "Roll #" << counter << " : 3\n\n";
		
		if(counter == 1)
		{
			system("PAUSE");
			lostGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 1 && r2 == 3 || r1 == 3 && r2 == 1 )
	{
		cout << "|=================|  |=================|\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |              O  |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|        O        |  |        O        |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |                 |\n"
			 << "|                 |  |  O              |\n"
			 << "|                 |  |                 |\n"
			 << "|=================|  |=================|\n\n"
			 << "Roll #" << counter << " : 4\n\n";
			 
			 if(counter == 1)
			 {
                    oR = 4;
					system("PAUSE");
					//roll = true;
			 }
             else
			 {
                    oR2 = 4;
					system("pause");
					//roll = false;
			 }
             if(oR == oR2 && counter >= 2)
             {
                    system("PAUSE");
                    winGame();
					//roll = true;
					game = true;
             }

	}
	
	if( r1 == 1 && r2 == 4 || r1 == 4 && r2 == 1 )
	{
        cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 5\n\n";
             
             if(counter == 1)
			 {
                    oR = 5;
					system("PAUSE");
					//roll = true;
			 }
             else
			 {
                    oR2 = 5;
					system("pause");
					//roll = false;
			 }
             if(oR == oR2 && counter >= 2)
             {
                    system("PAUSE");
                    winGame();
					//roll = true;
					game = true;
             }
    }
    
    if( r1 == 1 && r2 == 5 || r1 == 5 && r2 == 1 )
    {
        cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |        O        |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 6\n\n";
             
             if(counter == 1)
			 {
                    oR = 6;
					system("PAUSE");
					//roll = true;
			 }
             else
			 {
                    oR2 = 6;
					system("pause");
					//roll = false;
			 }
             if(oR == oR2 && counter >= 2)
             {
                    system("PAUSE");
                    winGame();
					//roll = true;
					game = true;
             }
    }
    
    if( r1 == 1 && r2 == 6 || r1 == 6 && r2 == 1 )
    {
        cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 7\n\n";
             
             if(counter == 1)
             {
					system("PAUSE");
					winGame();
					//roll = true;
					game = true;
             }
             else
             {
					system("PAUSE");
					lostGame();
					//roll = true;
					game = true;
             }
	}

    if( r1 == 2 && r2 == 2 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |              O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O              |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 4\n\n";
		
		if(counter == 1)
		{
			oR = 4;
			system("PAUSE");
			//roll = true;
		}
		else
		{
			oR2 = 4;
			system("pause");
			//roll = false;
		}
		if(oR == oR2 && counter >= 2)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 2 && r2 == 3 || r1 == 3 && r2 == 2 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |              O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |         O       |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O              |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
			 << "Roll #" << counter << " : 5\n\n";

	    if(counter == 1)
		{
			oR = 5;
			system("PAUSE");
			//roll = true;
		}
		else
		{
			oR2 = 5;
			system("pause");
			//roll = false;
		}

		if(oR == oR2 && counter >= 2)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 2 && r2 == 4 || r1 == 4 && r2 == 2 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 6\n\n";

		if(counter == 1)
		{
			oR = 6;
			system("PAUSE");
			//roll = true;
		}
		else
		{
			oR2 = 6;
			system("pause");
			//roll = false;
		}
		if(oR == oR2 && counter >= 2)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 2 && r2 == 5 || r1 == 5 && r2 == 2 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |        O        |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 7\n\n";

		if(counter == 1)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
		else
		{
			system("PAUSE");
			lostGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 2 && r2 == 6 || r1 == 6 && r2 == 2 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 8\n\n";

		if(counter == 1)
		{
			oR = 8;
		    system("PAUSE");
			//roll = true;
		}
		else
		{
			oR2 = 8;
			system("pause");
			//roll = false;
		}
		if(oR == oR2 && counter >= 2)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 3 && r2 == 3 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |              O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |        O        |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O              |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 6\n\n";

		if(counter == 1)
		{
			oR = 6;
			system("PAUSE");
			//roll = true;
		}
		else
		{
			oR2 = 6;
			system("pause");
			//roll = false;
		}
		if(oR == oR2 && counter >= 2)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 3 && r2 == 4 || r1 == 4 && r2 == 3 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 7\n\n";

		if(counter == 1)
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
		if(counter >= 2)
		{
			system("PAUSE");
			lostGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 3 && r2 == 5 || r1 == 5 && r2 == 3 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |        O        |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 8\n\n";

		if(counter == 1)
		{
			oR = 8;
			system("pause");
			//roll = true;
		}
		else
		{
			oR2 = 8;
			system("pause");
			//roll = false;
		}
		if( oR == oR2 && counter >= 2 )
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 3 && r2 == 6 || r1 == 6 && r2 == 3 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|              O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O              |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 9\n\n";

		if(counter == 1)
		{
			oR = 9;
			system("PAUSE");
			//roll = true;
		}
		else
		{
			oR2 = 9;
			system("pause");
			//roll = false;
		}
		if( oR == oR2 && counter >= 2 )
		{
			system("PAUSE");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 4 && r2 == 4 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 8\n\n";

		if(counter == 1)
		{
			oR = 8;
			system("pause");
			//roll = true;
		}
		else
		{
			oR2 = 8;
			system("pause");
			//roll = false;
		}
		if( oR == oR2 && counter >= 2 )
		{
			system("pause");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 4 && r2 == 5 || r1 == 5 && r2 == 4 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |        O        |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 9\n\n";

		if(counter == 1)
		{
			oR = 9;
			system("pause");
			//roll = true;
		}
		else
		{
			oR2 = 9;
			system("pause");
			//roll = false;
		}
		if( oR == oR2 && counter >= 2 )
		{
			system("pause");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 4 && r2 == 6 || r1 == 6 && r2 == 4 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 10\n\n";

		if(counter == 1)
		{
			oR = 10;
			system("pause");
			//roll = true;
		}
		else
		{
			oR2 = 10;
			system("pause");
			//roll = false;
		}
		if( oR == oR2 && counter >= 2 )
		{
			system("pause");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 5 && r2 == 5 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |        O        |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 10\n\n";

		if(counter == 1)
		{
			oR = 10;
			system("pause");
			//roll = true;
		}
		else
		{
			oR2 = 10;
			system("pause");
			//roll = false;
		}
		if( oR == oR2 && counter >= 2 )
		{
			system("pause");
			winGame();
			//roll = true;
			game = true;
		}
	}

	if( r1 == 5 && r2 == 6 || r1 == 6 && r2 == 5 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|        O        |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 11\n\n";

		if(counter == 1)
		{
			system("pause");
			winGame();
			//roll = true;
			game = true;
		}
		else
		{
			oR2 = 11;
			system("pause");
			//roll = true;
			game = true;
		}
	}

	if( r1 == 6 && r2 == 6 )
	{
		cout << "|=================|  |=================|\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|                 |  |                 |\n"
             << "|  O           O  |  |  O           O  |\n"
             << "|                 |  |                 |\n"
             << "|=================|  |=================|\n\n"
             << "Roll #" << counter << " : 12\n\n";

		if(counter == 1)
		{
			system("pause");
			lostGame();
			//roll = true;
			game = true;
		}
	
	}

  }
}

/**********************
**                   **
**     LOST GAME     **
**                   **
**********************/

void lostGame()
{
	char pA;

	system("CLS");
	cout << "\n\n\n\n\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$      You Craped Out!      $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  -----------------------  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$    Buh Bye! Play Again!   $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  -----------------------  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$     Game Created by :     $$\n"
		 << "\t\t\t$$        Brandon Wall       $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n"
		 << "\t\t\tPlay Again? (Y or N) : ";
	cin >> pA;

	if(pA == 'y')
	{
		playGame();

	}
}

/**********************
**                   **
**     QUIT GAME     **
**                   **
**********************/

void quitGame()
{
    system("CLS");
    cout << "\n\n\n\n\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$         You Quit!         $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  -----------------------  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  Buh Bye! Come Back Soon  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  -----------------------  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$     Game Created by :     $$\n"
		 << "\t\t\t$$        Brandon Wall       $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n\n";
		 
    system("PAUSE");
}

/*********************
**                  **
**     WIN GAME     **
**                  **
*********************/

void winGame()
{
	char pA;

    system("CLS");
    cout << "\n\n\n\n\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$          You Won!         $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  -----------------------  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  Buh Bye! Come Back Soon  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$  -----------------------  $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$     Game Created by :     $$\n"
		 << "\t\t\t$$        Brandon Wall       $$\n"
		 << "\t\t\t$$                           $$\n"
		 << "\t\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n"
		 << "\t\t\tPlay Again? (Y or N) : ";
	cin >> pA;

	if(pA == 'y')
	{
		playGame();
	}
}


P.S - Thank you for any help, suggestions, and advice! [Edited by - NUCLEAR RABBIT on June 6, 2006 11:24:03 AM]

Share this post


Link to post
Share on other sites
second problem.

to remove the warning simply add an explicit cast, this is jut because time_t might have more bits (64 probably, unsigned) then srand takes (32 unsigned).

make it:

srand((unsigned int)time(0));

Share this post


Link to post
Share on other sites
The second problem shouldn't be an error, but a warning. You can either ignore it or cast the return of time() to unsigned int: srand( (unsigned int)time(0) );
Also counter += 1; can be replaced by counter++; [smile]

Share this post


Link to post
Share on other sites
First problem, problem A.

You use a undefined local variable "game" in lostGame() ... perhaps you have a global in your stdafx? I don't know ... but in your playGame() you use a local, not a global variable - so the changes to the global variable in lostGame will not affect the local variable in playGame().

Haven't gotten further than that yet.

Share this post


Link to post
Share on other sites
This:

r1 = rand() % 6;
r2 = rand() % 6;

produces a random number in the range 0 to 5.

I think you want:

r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;

produces a random number between 0 and 5 and then adds 1 to it. So now you get the range 1 to 6.

I think part of your problem is that sometimes you are rolling a 0 and you have no condition to check for 0 that I saw ( I just quickly glanced over it ).

Hope that helps. Goodluck with it!

Share this post


Link to post
Share on other sites
My knowledge of programming for console projects is quite limited, but is there a difference between

system("pause");
and
system("PAUSE");

If the first one doesn't execute, your program will continue until it hits the second making it seem like it's skipping rolls when really it's executing two. Consider using getch(); instead.

Probably the best way to find out just what's going on would be to use the debugger to trace through your program. If you don't know how (and assuming VC Express 8 works like I think it does), place your cursor on a line you wish your program to run to and press the F9 key. This creates a "breakpoint" and a red circle should apear to the left of the line your on. Then press the F5 key. Your program will run to the line where the breakpoint is. Pressing F11 will then either enter the function you're on or step to the next line of code. F10 will just step to the next line of code. Pressing F5 will continue running the program from the current line until it either reaches another breakpoint or the program ends. As you step through your program, you can use other tools within the IDE to see the current value of your variables.

Share this post


Link to post
Share on other sites
Quote:
Original post by kseh
My knowledge of programming for console projects is quite limited, but is there a difference between

system("pause");
and
system("PAUSE");


DOS commands are not case-sensitive so it should not make a difference. You should probably use getch anyway though becuase system calls are not cross-platform.

Share this post


Link to post
Share on other sites
Well, I compiled, ran, and debugged the program. It apears as though what we have here is a debouncing issue. Basicly, whatever key is being pressed is being held down just a few milliseconds extra such that the next pause statement picks up the key press. It happens so fast it looks like rolls are being skipped. getch() all by itself seems to get the same problem. You want to use it in conjunction with _kbhit().

From Microsoft help files:

Example
// crt_kbhit.c
// compile with: /c
/* This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/


#include <conio.h>
#include <stdio.h>

int main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( "Hit me!! " );

/* Use _getch to throw key away. */
printf( "\nKey struck was '%c'\n", _getch() );
}

Sample Output
Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!!
Key struck was 'q'



(edit)
I guess I should mention that what you probably wanna do is call _kbhit() at the beginning of your while loop to make sure that the key that was pressed from the system("pause"); has been released.

[Edited by - kseh on June 6, 2006 3:15:13 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this