| TechKidd (2) | |
|
#include <iostream> //Allows input and output #include <cstdlib> //Allows use of the rand() function #include <ctime> //Allows seeding of the random number generator using namespace std; //FUNCTION PROTOTYPES int RollDie(int); //Generates random number between 1 & n simulating a die roll. int RollDice(); //Simulates rolling of both dice and returns their value. void SeedGenerator(); //Seeds random number generator. void ShowDice(); //Shows the value [numerically of the global dice variables]. void DrawDie(int); //Draws the corresponding value of an int 1-6 as a text rendered die. //Created function to generate random number, draw and score the dice and report the results to the player. int ScoreTheDie(int n) { cout<<"What is your n value?\n"; cin >> n ; } int main() { //Roll Number One cout<<"First Roll\n"; //Hold window open system("PAUSE"); srand(time(0)); int Roll_One; int n; Roll_One = ScoreTheDie(n); int D1; int D2; D1 = rand()%(n+1); D2 = rand()%(n+1); //Draws the dice according to the number that was generated DrawDie(D1); DrawDie(D2); //Prints the results to the screen cout<<"Die 1 ="<<D1<<endl; cout<<"Die 2 ="<<D2<<endl; return(D1+D2); //Runs the results of roll one through the rules and conditions of the game //ScoreTheDie() if((Roll_One==2)||(Roll_One==3)||(Roll_One)){ cout<<"You rolled a(n) " <<Roll_One<< " Sorry, You Crap Out \n"; } else if ((Roll_One==7)||(Roll_One==11)){ cout<<"You rolled a(n) " <<Roll_One<< " Congratulations, You WIN!!! \n"; } else{ cout<<"You point is "<<Roll_One<<endl; //Preparation for the while loop that controls the second roll int stop; stop = false; while (stop==false){ //While the condition is not true, proceed with the program system("PAUSE"); cout<<"Second Roll\n"; int Roll_Two; //Commence the second roll of the game Roll_Two = ScoreTheDie(n); //Process Roll Two through the rules and conditions of craps if (Roll_Two == 7) { cout<<"You rolled a(n) " <<Roll_Two<< "Sorry, You Crap Out\n"; } else if (Roll_Two == Roll_One){ cout<<"You rolled a(n) " <<Roll_Two<< "CONGRATULATIONS, YOU WIN!!! \n"; stop = true; } //If none of the conditions are met then roll again else { cout << "Roll Again"; } } } //Hold Console Window open until a key is pressed system("PAUSE"); return 0; }//end main //FUNCTIONS & SUBROUTINES void DrawDie(int IntValue){ //DRAWS THE VALUE OF A D6 [SIX SIDED DIE] TO THE SCREEN if (IntValue == 1) {//then cout << "+-------+" << "\n"; cout << "| |" << "\n"; cout << "| * |" << "\n"; cout << "| |" << "\n"; cout << "+-------+" << "\n"; }//end if if (IntValue == 2) {//then cout << "+-------+" << "\n"; cout << "| * |" << "\n"; cout << "| |" << "\n"; cout << "| * |" << "\n"; cout << "+-------+" << "\n"; }//end if if (IntValue == 3) {//then cout << "+-------+" << "\n"; cout << "| * |" << "\n"; cout << "| * |" << "\n"; cout << "| * |" << "\n"; cout << "+-------+" << "\n"; }//end if if (IntValue == 4) {//then cout << "+-------+" << "\n"; cout << "| * * |" << "\n"; cout << "| |" << "\n"; cout << "| * * |" << "\n"; cout << "+-------+" << "\n"; }//end if if (IntValue == 5) {//then cout << "+-------+" << "\n"; cout << "| * * |" << "\n"; cout << "| * |" << "\n"; cout << "| * * |" << "\n"; cout << "+-------+" << "\n"; }//end if if (IntValue == 6) {//then cout << "+-------+" << "\n"; cout << "| * * |" << "\n"; cout << "| * * |" << "\n"; cout << "| * * |" << "\n"; cout << "+-------+" << "\n"; }//end if }//end sub | |
|
Last edited on
|
|
| TechKidd (2) | |
| I keep getting an error from this program, could anyone tell me what is wrong? It normally says that ScoreTheDie() has to return a value. What does that mean? | |
|
|
|
| eraggo (146) | |||||
Notice that your function has return type of int. Also you have in one line:
which hopes to get value to variable Roll_Two. Put return-statelement to ScoreTheDie()-function. | |||||
|
|
|||||