1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <iostream>
#include <cstdlib>
#include <string>
void rolldice (int num1, int num2, int num3, int num4, int num5, int num6);//function prototype for the dice rolls
int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, num6 = 0;/*integer decleration of the six numbers equaled to zero
such that the count starts from 1. */
int player1score, player2score;//integer decleration of players one and twos score
int main()
{
srand(time(0));//This is declared to help in the generation of random numbers by seeding rand with a starting value.
std::string player1;//string decleration for the text that is to be inputed for the first player
std::string player2;//string decleration for the text that is to be inputed for the second player
int roll = 1;//allows player2 to roll
//Welcome message that appears at start of program with goal of the game
std::cout <<"***************************************************************************\n";
std::cout << " Welcome to the Dice Roller! The simple rule of this game is to roll \n";
std::cout <<"\n";
std::cout << " the die seven times and score up to 10,000 or more points. \n\n";
std::cout <<"***************************************************************************\n";
std::cout <<"\n";
std::cout << "Player 1, please enter your name: ";//output message for first palyer
std::cin >> player1;//player1 types desired name
std::cout << "\nWelcome, " << player1 << ". \n\n";
std::cout << "Player 2, please enter your name: ";//output message for first palyer
std::cin >> player2;//player2 types desired name
while (player2 == player1)//Loop which redirects player2 input a different name if player1 has similar name
{
std::cout << "Player 1 has already chosen this name!\n\n";
std::cout << "Player 2, please enter your name: ";
std::cin >> player2;
}
std::cout << "\nWelcome, " << player2 << ". \n\n";
std::cout << "Let's begin!\n\n";
std::cout << player1<<" goes first, press enter to continue...\n";
std::cin.get();
std::cin.ignore();
for (int roll7 = 0; roll7 < 7; roll7 ++)//roll7 Loop which rolls seven times for player1
{
std::cout << player1 << " rolled: "; //Random numbers 1-6 are generated and outputted from rolldice function
rolldice (num1, num2, num3, num4, num5, num6);
}
std::cout <<"\n";
std::cout << player1 << " scored " << player1score << " points!\n\n";//outputted player1 score after rolls
std::cout << "Your turn, " << player2 << ". Enter 1 to roll :";//start of second players roll
std::cin >> roll;//inputs 1 to roll
for (int roll7 = 0; roll7 < 7; roll7 ++)//roll7 Loop which rolls seven times for player1
{
std::cout << player2 << " rolled : "; //Random numbers 1-6 are generated and outputted from rolldice function
rolldice (num1, num2, num3, num4, num5, num6);
}
std::cout <<"\n";
std::cout << player2 <<" scored " << player2score << " points!\n\n";//outputted player1 score
//Loop which determines who wins if player1score is greater than player2score player1 wins if not then player2 wins
if (player1score > player2score)
std::cout << player1 <<" Wins!! \n";
else if (player1score < player2score)
std::cout << player2 <<" Wins!! \n";
else if (player1score == player2score)
std::cout << player1 << " and " << player2 << " win! They both got the same scores! \n";
system ("pause");
}
void rolldice (int num1, int num2, int num3, int num4, int num5, int num6)//voided rolldice function for generation of results
{
num1 = rand() % 6 + 1; //randomly generates numbers from 1 to 6 for all 6 dice
num2 = rand() % 6 + 1;
num3 = rand() % 6 + 1;
num4 = rand() % 6 + 1;
num5 = rand() % 6 + 1;
num6 = rand() % 6 + 1;
std::cout << " " << num1 << " " << num2 << " " << num3 << " " << num4 /*results will return the amount of 1's to 6's */
<< " " << num5 << " " << num6 << "\n"; /*that are randomly generated */
int total1 = num1 * 1 * 100; //for all 1's rolles its multiplied by 100
int total2 = num2 * 2 * 100; //for all 2's rolles its multiplied by 100
int total3 = num3 * 3 * 100; //for all 3's rolles its multiplied by 100
int total4 = num4 * 4 * 100; //for all 4's rolles its multiplied by 100
int total5 = num5 * 5 * 50; //ecah 5 scores 50 points.
int total6 = num6 * 6 * 100; //for all 6's rolles its multiplied by 100
//After totals of each side 1-6 is calculated it is scored as player1score
player1score = total1 + total2 + total3 + total4 + total5 + total6;
//After totals of each side 1-6 is calculated it is scored as player1score
player2score = total1 + total2 + total3 + total4 + total5 + total6;
}//end of program
|