Sign in to follow this  
GL_aLpHa

im done..now i need a critic

Recommended Posts

GL_aLpHa    118
Hi, I just actually 'finished' my first game. I've written other programs in C++, and I have enough experience to go further into game programming, but this was just a test to see if I got the right game structure/loop. I was just wondering if one of you guys could critic or provide short cuts for the code below. Everything works. The rules of the game can be found here. Homework #2
[SOURCE]
#include <string.h>
#include <iostream>
#include <time.h>

using namespace std;

void Menu();
/* Menu()--
     Displays a Menu for the User.
*/
                
void GameLoop();
/* GameLoop--
     The Main Game Loop(checks if the User wants to quit(quit=true),
     or if the game is over(done=true).
*/
               
int QuitMessage();
/* QuitMessage()--
     If User wants to quit(quit=true,done=true), displays quit message.
     If User wants to start game over(quit=false,done=true), goes back to MainLoop().
*/
                                        
int rollDie();
/* rollDie()--
     Simulates rolling of 2 die. Returns sum of die.
*/

void DisplayDie(int die1, int die2);
/* DisplayDie()--
     Displays die1 and die2 in the window.
*/

int firstRoll();
/* firstRoll()--
     Simulates the first roll, tests the sum of the die, and acts accordingly.
*/

int makePoint(int point);
/* makePoint()--
     Takes the die sum from firstRoll() as the current point(or sum), and acts accordingly.
     Used for future rolls.
*/

int die1;   //Die 1
int die2;   //Die 2
int diesum; //Sume of Die

// Die goes from 1-6
const int LOW = 1;
const int HIGH = 6;

bool done=false; //MainLoop Bool
bool quit=false; //QuitMessage Bool

int main()
{
    srand(static_cast<unsigned int>(time(0)));     //Random Seed
    GameLoop();                                    //Main GameLoop
    return 0;
}

//////////////////////
///// GameLoop() /////
//////////////////////
void GameLoop()
{
    done=false;           // Changes done to false everytime GameLoop is called.
    while(!done)          // While done=false, call Menu().
    {
       Menu();
    }
    QuitMessage();        // After done=true, call QuitMessage().
}

/////////////////////////
///// QuitMessage() /////
/////////////////////////
int QuitMessage()
{
    if(quit==true)        // If user really wants to quit, clear screen and quit.
    {
      system("cls");
      cout<<"\n\n\t\t\tThank You for playing Craps!";
      cout<<"\n\t\t\t       Quitting.....\n\n\t\t\t";
      system("PAUSE");
    }
    else
    {
              char answer;                                       
              cout<<"\n";    
              cout<<"\n\t\t\t  ************************";
              cout<<"\n\t\t\t  ||      Try Again?    ||";
              cout<<"\n\t\t\t  ||    (Y)es or (N)o   ||";
              cout<<"\n\t\t\t  ************************";
              cout<<"\n\t\t\t          -->: ";
              cin>>answer;
              // Test user input
              if(answer == 'y' || answer == 'Y')            // If yes, call Main game loop.
              {                                                  
                        GameLoop();                              
              }                                                  
              else if(answer == 'n' || answer == 'N')       // If no, user wants to quit,        
              {                                             // and displays quit message.        
                        quit=true;                                  
                        QuitMessage();                           
              }
              else                                          // Else, invalid value, do default.
              {
                  cout<<"\n\t\t\tInvalid Value! Going to Menu()!";
                  GameLoop();
              }
    }
}

//////////////////
///// Menu() /////
//////////////////
void Menu()
{
    char answer;
    system("cls");
    cout<<"\n\t\t\t     ___________________ ";
    cout<<"\n\t\t\t    |                   |";
    cout<<"\n\t\t\t    | Welcome to Craps! |";
    cout<<"\n\t\t\t    |      Press:       |";
    cout<<"\n\t\t\t    |   (P) to Play     |";
    cout<<"\n\t\t\t    |   (Q) to Quit     |";
    cout<<"\n\t\t\t    |-------------------|";
    cout<<"\n\t\t\t    |      Rules:       |";
    cout<<"\n\t\t\t    | To Win-           |";
    cout<<"\n\t\t\t    | Roll 7 or 11 on   |";
    cout<<"\n\t\t\t    | first roll, or    |";
    cout<<"\n\t\t\t    | roll the same sum,|";
    cout<<"\n\t\t\t    | or \"point\", on    |";
    cout<<"\n\t\t\t    | future rolls.     |";
    cout<<"\n\t\t\t    |                   |";
    cout<<"\n\t\t\t    | Lose-             |";
    cout<<"\n\t\t\t    | Roll 2, 3, or 12  |";
    cout<<"\n\t\t\t    | on first roll, or |";
    cout<<"\n\t\t\t    | roll a 7 on       |";
    cout<<"\n\t\t\t    | future rolls.     |";
    cout<<"\n\t\t\t    |___________________|";
    cout<<"\n\t\t\t          -->: ";
    cin>>answer;
    system("cls");
    // Tests user input
    if(answer == 'P' || answer == 'p')                // If play, make first roll,
    {                                                 // and if done=false, make point
                   int result;                        // according to return value of
                   result=firstRoll();                // firstRoll().
                   if(done==false)
                   {
                       makePoint(result);
                   }         
    }
    else if(answer == 'q' || answer == 'Q')           // If quit, user wants to quit
    {                                                 // and the game loop is done.
                 quit=true;
                 done=true;
    }
    else                                              // If wrong value typed in, do default
    {
         cout<<"\n\t\t\tInvalid Value! Going back to Menu()!";
         cin.ignore();
         cin.get();
         Menu();
    }
}

/////////////////////
///// rollDie() /////
/////////////////////            
int rollDie()
{
    int diesum2;            
    die1 = rand() % (HIGH - LOW + 1) + LOW;  // Uses rand to generate random numbers
    die2 = rand() % (HIGH - LOW + 1) + LOW;  // from 1-6, and assigns them to die1 and die2.
    diesum2=die1+die2;                       // Die sum = die1 + die2.
    DisplayDie(die1,die2);
    cout<<"\n\t\t       *****************************";
    cout<<"\n\t\t        You have rolled a " << die1   <<" and a "<<die2;
    cout<<"\n\t\t        With a sum of >>>> "<< diesum2 <<" <<<<";
    cout<<"\n\t\t       *****************************";
    return diesum2;                               // Returns some of the two die
}

///////////////////////
///// firstRoll() /////
///////////////////////
int firstRoll()
{
    diesum = rollDie();                           // Die sum = return value of rollDie().
    
    if(diesum == 7 || diesum == 11)               // If diesum = 7 or 11,
    {                                             // display winning message, and  
         cout<<"\n\t\t\t\t  You win!\n";          // game loop is done.
         cin.ignore();
         cin.get();
         done=true;
    }
    else if(diesum == 2 || diesum == 3 || diesum == 12) // If diesum = 2, 3, or 12,
    {                                                   // display losing message, and
         cout<<"\n\t\t\t\t  You lose!\n";               // game loop is done.
         cin.ignore();
         cin.get();
         done=true;
    }
    else                                                // Else, display continue message,
    {                                                   // and return diesum.
         cout<<"\n\t\t\t\tKeep rolling!\n";
         cin.ignore();
         cin.get();
         return diesum;
    }
}

/////////////////////
///// makePoint /////
/////////////////////
int makePoint(int point)
{  
   if(point==0)                                           // If somehow point = 0,
   {                                                      // display error message, and
               cout<<"\n\n\t\t\t Point = 0, quitting..."; // game loop is done, and user
               quit=true;                                 // is forced to quit.
               done=true;
               cin.get();
   } 
   system("cls");  
   cout<<"\n\t\t-Now you must roll a sum, or \"point\", of "<<point<<" again, to WIN!";
   cin.get();
   cout<<"\n\t\t--However, you cannot roll a sum of 7, or you will LOSE!";
   cin.get();
   cout<<"\n\t\t---Think you can do it!?";
   cin.get();
   cout<<"\n\t\t----LET'S ROLL THE DICE!!!!";
   cin.get();
   while(!done)                                        // While done=false, display
   {                                                   // current point value, and
    system("cls");                                     // roll the die.
    cout<<"\n\t\t\tCurrent Point: "<<point;
    cout<<"\n\t\t\tRolling Die....";               
    diesum=rollDie();                                  
    cin.get();                                         
    if(diesum == 7)                              // If die sum is 7, display
    {                                            // losing message, and gameloop
              cout<<"\n";                        // is done.
              cout<<"\n\t\t       *****************************************";
              cout<<"\n\t\t       * AWWWW!!! YOU HIT THE 7!!! YOU LOSE!!! *";
              cout<<"\n\t\t       *****************************************";
              cin.get();
              done=true;
              break;
    }
    else if(diesum == point)                // If dice sum is point value, display                 
    {                                       // winning message, and gameloop is 
              cout<<"\n";                   // done.
              cout<<"\n\t\t       :::::::::::::::::::::::::::::::::::::::::::";
              cout<<"\n\t\t       : YEA!!! YOU HIT YOUR POINT!!! YOU WIN!!! :";
              cout<<"\n\t\t       :::::::::::::::::::::::::::::::::::::::::::";
              cin.get();
              done=true;
              break;
    }
   }
}

////////////////////////
///// DisplayDie() /////
////////////////////////
void DisplayDie(int die1, int die2)
{
     string dice[6][6];
     
     dice[0][0]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|           ||           |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[0][1]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|           ||  0        |" 
                 "\n\t\t\t|     0     ||           |"
                 "\n\t\t\t|           ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[0][2]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|           ||  0        |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|           ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[0][3]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|           ||  0     0  |" 
                 "\n\t\t\t|     0     ||           |"
                 "\n\t\t\t|           ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";                      
                
     dice[0][4]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|           ||  0     0  |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|           ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[0][5]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|           ||  0     0  |" 
                 "\n\t\t\t|     0     ||  0     0  |"
                 "\n\t\t\t|           ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[1][0]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||           |" 
                 "\n\t\t\t|           ||     0     |"
                 "\n\t\t\t|        0  ||           |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[1][1]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0        |" 
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|        0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[1][2]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0        |" 
                 "\n\t\t\t|           ||     0     |"
                 "\n\t\t\t|        0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[1][3]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0     0  |" 
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|        0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";           
                
     dice[1][4]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0     0  |" 
                 "\n\t\t\t|           ||     0     |"
                 "\n\t\t\t|        0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[1][5]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0     0  |" 
                 "\n\t\t\t|           ||  0     0  |"
                 "\n\t\t\t|        0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[2][0]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||           |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|        0  ||           |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[2][1]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0        |" 
                 "\n\t\t\t|     0     ||           |"
                 "\n\t\t\t|        0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[2][2]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0        |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|        0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[2][3]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0     0  |" 
                 "\n\t\t\t|     0     ||           |"
                 "\n\t\t\t|        0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[2][4]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0     0  |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|        0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[2][5]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0        ||  0     0  |" 
                 "\n\t\t\t|     0     ||  0     0  |"
                 "\n\t\t\t|        0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[3][0]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||           |" 
                 "\n\t\t\t|           ||     0     |"
                 "\n\t\t\t|  0     0  ||           |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[3][1]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0        |" 
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[3][2]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0        |" 
                 "\n\t\t\t|           ||     0     |"
                 "\n\t\t\t|  0     0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[3][3]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[3][4]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|           ||     0     |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";                      
                
     dice[3][5]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|           ||  0     0  |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[4][0]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||           |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|  0     0  ||           |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[4][1]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0        |" 
                 "\n\t\t\t|     0     ||           |"
                 "\n\t\t\t|  0     0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[4][2]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0        |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|  0     0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[4][3]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|     0     ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[4][4]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|     0     ||     0     |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";           
                
     dice[4][5]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|     0     ||  0     0  |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                
     dice[5][0]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||           |" 
                 "\n\t\t\t|  0     0  ||     0     |"
                 "\n\t\t\t|  0     0  ||           |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[5][1]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0        |" 
                 "\n\t\t\t|  0     0  ||           |"
                 "\n\t\t\t|  0     0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[5][2]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0        |" 
                 "\n\t\t\t|  0     0  ||     0     |"
                 "\n\t\t\t|  0     0  ||        0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[5][3]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|  0     0  ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[5][4]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|  0     0  ||     0     |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                 
     dice[5][5]= "\n\t\t\t ___________  ___________ "
                 "\n\t\t\t|           ||           |"
                 "\n\t\t\t|  0     0  ||  0     0  |" 
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|  0     0  ||  0     0  |"
                 "\n\t\t\t|___________||___________|\n";
                                                                                                  
    if(die1 == 1 && die2 == 1)
            cout<<dice[0][0];
    else if(die1 == 1 && die2 == 2)
            cout<<dice[0][1];
    else if(die1 == 1 && die2 == 3)
            cout<<dice[0][2];
    else if(die1 == 1 && die2 == 4)
            cout<<dice[0][3];
    else if(die1 == 1 && die2 == 5)
            cout<<dice[0][4];
    else if(die1 == 1 && die2 == 6)
            cout<<dice[0][5];
    else if(die1 == 2 && die2 == 1)
            cout<<dice[1][0];
    else if(die1 == 2 && die2 == 2)
            cout<<dice[1][1];
    else if(die1 == 2 && die2 == 3)
            cout<<dice[1][2];
    else if(die1 == 2 && die2 == 4)
            cout<<dice[1][3];
    else if(die1 == 2 && die2 == 5)
            cout<<dice[1][4];
    else if(die1 == 2 && die2 == 6)
            cout<<dice[1][5];
    else if(die1 == 2 && die2 == 1)
            cout<<dice[2][0];
    else if(die1 == 3 && die2 == 2)
            cout<<dice[2][1];
    else if(die1 == 3 && die2 == 3)
            cout<<dice[2][2];
    else if(die1 == 3 && die2 == 4)
            cout<<dice[2][3];
    else if(die1 == 3 && die2 == 5)
            cout<<dice[2][4];
    else if(die1 == 3 && die2 == 6)
            cout<<dice[2][5];
    else if(die1 == 3 && die2 == 1)
            cout<<dice[3][0];
    else if(die1 == 4 && die2 == 2)
            cout<<dice[3][1];
    else if(die1 == 4 && die2 == 3)
            cout<<dice[3][2];
    else if(die1 == 4 && die2 == 4)
            cout<<dice[3][3];
    else if(die1 == 4 && die2 == 5)
            cout<<dice[3][4];
    else if(die1 == 4 && die2 == 6)
            cout<<dice[3][5];
    else if(die1 == 4 && die2 == 1)
            cout<<dice[4][0];
    else if(die1 == 5 && die2 == 2)
            cout<<dice[4][1];
    else if(die1 == 5 && die2 == 3)
            cout<<dice[4][2];
    else if(die1 == 5 && die2 == 4)
            cout<<dice[4][3];
    else if(die1 == 5 && die2 == 5)
            cout<<dice[4][4];
    else if(die1 == 5 && die2 == 6)
            cout<<dice[4][5];
    else if(die1 == 5 && die2 == 1)
            cout<<dice[5][0];
    else if(die1 == 6 && die2 == 2)
            cout<<dice[5][1];
    else if(die1 == 6 && die2 == 3)
            cout<<dice[5][2];
    else if(die1 == 6 && die2 == 4)
            cout<<dice[5][3];
    else if(die1 == 6 && die2 == 5)
            cout<<dice[5][4];
    else if(die1 == 6 && die2 == 6)
            cout<<dice[5][5];               
}
[/SOURCE]
[/source]

Share this post


Link to post
Share on other sites
Lanky007    133
works nicely. except I had to change the header to "#include <string>"

and also there were some functions which were supposed to return an int but never did, so I added "return 0;" for those so it would compile. does you compiler let your get away with that stuff?

Share this post


Link to post
Share on other sites
gumpy    795
instead of <string.h> and <time.h> you should be using <string> and <ctime>. also, QuitMessage and makePoint are declared as returning an int value, yet neither one returns anything. firstRoll is also declared as returning an int, but doesn't always do so. what compiler are you working with?

Share this post


Link to post
Share on other sites
GL_aLpHa    118
haha... whoops... I remember changing to int QuitMessage() but never changed it back to void once i found an easier way to get the code working...
as for the makePoint function... that was my error...
I am using Dev C++ 5.
And in the firstRoll function...i could just do this... and it would work the same?
[SOURCE]
int firstRoll()
{
diesum = rollDie(); // Die sum = return value of rollDie().

if(diesum == 7 || diesum == 11) // If diesum = 7 or 11,
{ // display winning message, and
cout&lt;&lt;"\n\t\t\t\t You win!\n"; // game loop is done.
cin.ignore();
cin.get();
done=true;
return 0;
}
else if(diesum == 2 || diesum == 3 || diesum == 12) // If diesum = 2, 3, or 12,
{ // display losing message, and
cout&lt;&lt;"\n\t\t\t\t You lose!\n"; // game loop is done.
cin.ignore();
cin.get();
done=true;
return 0;
}
else // Else, display continue message,
{ // and return diesum.
cout&lt;&lt;"\n\t\t\t\tKeep rolling!\n";
cin.ignore();
cin.get();
return diesum;
}
}
[/SOURCE]


And another question, if you look on the link i provided above, you will see the conditions for making the game Craps. It says that firstRoll must return 0 for a winning roll, and return -1 for a losing roll. What is the difference? And how would it affect the program? I have the same question for the makePoint function.

Thank you for the replies.

Share this post


Link to post
Share on other sites
EricmBrown    124
looks good. the only thing i would change is instead of saying


if(die1 == 1 && die2 == 1)
cout<<dice[0][0];
else if(die1 == 1 && die2 == 2)
cout<<dice[0][1];
else if(die1 == 1 && die2 == 3)
cout<<dice[0][2];
else if(die1 == 1 && die2 == 4)
cout<<dice[0][3];
else if(die1 == 1 && die2 == 5)
cout<<dice[0][4];
else if(die1 == 1 && die2 == 6)
cout<<dice[0][5];
else if(die1 == 2 && die2 == 1)
cout<<dice[1][0];
else if(die1 == 2 && die2 == 2)
cout<<dice[1][1];
else if(die1 == 2 && die2 == 3)
cout<<dice[1][2];
else if(die1 == 2 && die2 == 4)
cout<<dice[1][3];
else if(die1 == 2 && die2 == 5)
cout<<dice[1][4];
else if(die1 == 2 && die2 == 6)
cout<<dice[1][5];
else if(die1 == 2 && die2 == 1)
cout<<dice[2][0];
else if(die1 == 3 && die2 == 2)
cout<<dice[2][1];
else if(die1 == 3 && die2 == 3)
cout<<dice[2][2];
else if(die1 == 3 && die2 == 4)
cout<<dice[2][3];
else if(die1 == 3 && die2 == 5)
cout<<dice[2][4];
else if(die1 == 3 && die2 == 6)
cout<<dice[2][5];
else if(die1 == 3 && die2 == 1)
cout<<dice[3][0];
else if(die1 == 4 && die2 == 2)
cout<<dice[3][1];
else if(die1 == 4 && die2 == 3)
cout<<dice[3][2];
else if(die1 == 4 && die2 == 4)
cout<<dice[3][3];
else if(die1 == 4 && die2 == 5)
cout<<dice[3][4];
else if(die1 == 4 && die2 == 6)
cout<<dice[3][5];
else if(die1 == 4 && die2 == 1)
cout<<dice[4][0];
else if(die1 == 5 && die2 == 2)
cout<<dice[4][1];
else if(die1 == 5 && die2 == 3)
cout<<dice[4][2];
else if(die1 == 5 && die2 == 4)
cout<<dice[4][3];
else if(die1 == 5 && die2 == 5)
cout<<dice[4][4];
else if(die1 == 5 && die2 == 6)
cout<<dice[4][5];
else if(die1 == 5 && die2 == 1)
cout<<dice[5][0];
else if(die1 == 6 && die2 == 2)
cout<<dice[5][1];
else if(die1 == 6 && die2 == 3)
cout<<dice[5][2];
else if(die1 == 6 && die2 == 4)
cout<<dice[5][3];
else if(die1 == 6 && die2 == 5)
cout<<dice[5][4];
else if(die1 == 6 && die2 == 6)
cout<<dice[5][5];



you could just say

cout<<dice[die1-1][die2-1];

Share this post


Link to post
Share on other sites
rip-off    10979
I recommend you add -Wall to your compiler options. It will let you know about some of the things that have been mentioned ( forgetting to return a value, etc ).

Add it to Project->Project Options->Parameters->c and c++ compilers.

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