All,
I have some code here that I need some help on. Some background information on this project is, two die are tossed (as you know, faces of each dice are numbered 1 through 6.) If sum of the faces landing up is 2, 3, 6, or 7 then Shooy-Mooy wins. If the sum of the faces that land up is 4, 5, 11, or 12 then the opponent wins. Otherwise the toss is a draw.
I'm on the last part of this assignment. What's left is that I have to determine the total number of tosses, Shooy-Mooy’s score, Opponent’s score, the number of tosses that resulted in a draw, and the overall winner. So far, I have written this code, but I am not sure where I should do the calculations. Any help would be greatly appreciated.
I have some code here that I need some help on. Some background information on this project is, two die are tossed (as you know, faces of each dice are numbered 1 through 6.) If sum of the faces landing up is 2, 3, 6, or 7 then Shooy-Mooy wins. If the sum of the faces that land up is 4, 5, 11, or 12 then the opponent wins. Otherwise the toss is a draw.
I'm on the last part of this assignment. What's left is that I have to determine the total number of tosses, Shooy-Mooy’s score, Opponent’s score, the number of tosses that resulted in a draw, and the overall winner. So far, I have written this code, but I am not sure where I should do the calculations. Any help would be greatly appreciated.
Code:
#include <iostream>
#include <cstdlib> //access to rand() function
using namespace std;
#define DASHES "-----------------------------------------------------------"
#define SEPARATOR "--------------"
#define TOSS 20
int main (void)
{
// prototypes
void top_of_page_info (void);
void welcome_header (void);
int toss_die (void);
void toss_winner (int &dice1, int &dice2);
void keep_output_window_open (void);
//variable declarations
int dice1, dice2; // variables for storing random #'s for both die.
int i; // counter
// functions
top_of_page_info ();
welcome_header ();
//srand(time(NULL)); //To seed or not to seed, that is the question...
// process 20 tosses of the dice
// call functions, toss_die() and toss_winner()
for (i = 1; i <= TOSS; i++) // process info on 20 tosses
{
dice1 = toss_die();
dice2 = toss_die();
toss_winner (dice1, dice2);
}
cout << endl << endl;
cout << "Total Number of Tosses = " << i-1 << "." << endl << endl;
cout << "Shooy-Mooy's Score = " << "TBD" << "." << endl;
cout << "Opponent" << "'s Score = " << "TBD" << "." << endl;
cout << "Number of Draws = " << "TBD" << "." << endl;
// function
keep_output_window_open ();
return 0;
} // end of main program
//=========================end of main()=======================================
//*****************************************************************************
// This method/function prints student info on top of page.
//-----------------------------------------------------------------------------
// Parameters Passed : none
// Value(s) Returned : none
// Local Variables : none
//-----------------------------------------------------------------------------
// Constant Identifier Type Description
// NAME string String of characters
//*****************************************************************************
#define NAME "Todd McNeil"
void top_of_page_info (void)
{
cout << DASHES;
cout << "\n\t\tProgrammer Name: " << NAME;
cout << "\n\t\tSection: CSI 155/Section 875";
cout << "\n\t\tLab/Project No.: Lab #3 Part B";
cout << "\n\t\tDate : 02/16/2006\n";
cout << DASHES << endl << endl << endl;
}
//-------------------------end top_of_page_info--------------------------------
//*****************************************************************************
// This method/function prints student info on top of page.
//-----------------------------------------------------------------------------
// Parameters Passed : none
// Value(s) Returned : none
// Local Variables : name char
//*****************************************************************************
void welcome_header (void)
{
char name[15]; //user input, opponent's name
cout << "Please Enter Your Name: ";
cin >> name;
cout << endl << DASHES << endl << endl;
cout << "\t Tossing Die Game - Shooy-Mooy vs. " << name;
cout << endl << "\t\tNo Seed Supplied for this Run";
cout << endl << endl << "\t\t " << SEPARATOR << endl << endl;
}
//-------------------------end welcome_header--------------------------------
//*****************************************************************************
// This method/function generates a random number between 1 and 6.
//-----------------------------------------------------------------------------
// Parameters Passed : none
// Value(s) Returned : random number
// Local Variables : none
//*****************************************************************************
int toss_die(void)
{
return(rand() % 6 + 1);
}
//---------------------------- end toss_die------------------------------------
//*****************************************************************************
// This method/function determines the winner of the toss
//-----------------------------------------------------------------------------
// Parameters Passed : none
// Value(s) Returned : random number
// Local Variables : none
//*****************************************************************************
void toss_winner(int &dice1, int &dice2)
{
int sum; // sum of each roll
sum = dice1 + dice2;
switch (sum)
{
case 2: cout << "Him" << endl;
//smScore = smScore + 2;
break;
case 3: cout << "Him" << endl;
//smScore = smScore + 3;
break;
case 6: cout << "Him" << endl;
//smScore = smScore + 6;
break;
case 7: cout << "Him" << endl;
//smScore = smScore + 7;
break;
case 4: cout << "Me" << endl;
//oppScore = oppScore + 4;
break;
case 5: cout << "Me" << endl;
//oppScore = oppScore + 5;
break;
case 11: cout << "Me" << endl;
//oppScore = oppScore + 11;
break;
case 12: cout << "Me" << endl;
//oppScore = oppScore + 12;
break;
default: cout << "Draw" << endl;
//draw = draw + draw;
break;
}
}
//---------------------------- end toss_die------------------------------------
//*****************************************************************************
// This function keeps the window open to copy the output.
//-----------------------------------------------------------------------------
// Parameters Passed : none
// Value(s) Returned : none
// Local Variables : ch
//-----------------------------------------------------------------------------
//*****************************************************************************
void keep_output_window_open (void)
{
char ch;
cout << "\n******************That's All for Today*********************\n";
cout << "\n\nPress any letter or digit key to exit: ";
cin >> ch;
}
//---------------end keep_window_open------------------------------------------