Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include <ctime>
- #include <sstream>
- int countChar(std::string s, char c)
- {
- int count = 0;
- for(unsigned i = 0; i < s.size(); i++)
- {
- if(s[i] == c)
- {
- count++;
- }
- }
- return count;
- }
- int main() {
- srand((unsigned) time(0));
- bool upSecOccupied[6] = {false, false, false, false, false,
- false}; //aces twos threes fours fives sixes; 35 bonus if 63+
- bool loSecOccupied[7] = {false, false, false, false, false, false,
- false}; //3kind 4kind fullhouse smstr lgstr yahtzee chance
- int upSecScore[6] = {};
- int loSecScore[7] = {};
- int yahtzeeCount = 0;
- std::string keptDice;
- int numDiceKept = 0;
- int firstRoll;
- int seconRoll;
- int thirdRoll;
- int fourtRoll;
- int fifthRoll;
- std::string scoreSection;
- bool upSecCanScore[6] = {false, false, false, false, false, false};
- bool loSecCanScore[7] = {false, false, false, false, false, false, false};
- std::string output = "You rolled: ";
- for (int i = 1; i <= 13; i++) //i = turn number
- {
- keptDice = "";
- numDiceKept = 0;
- firstRoll = 0;
- seconRoll = 0;
- thirdRoll = 0;
- fourtRoll = 0;
- fifthRoll = 0;
- for(int index = 0; index < 7; index++)
- {
- if(index < 6)
- {
- upSecCanScore[index] = false;
- }
- loSecCanScore[index] = false;
- }
- std::cout << "Starting a new turn." << std::endl;
- for (int j = 1; j <= 3; j++) //j = number of rolls
- {
- output = "You rolled: ";
- if(numDiceKept < 5)
- {
- numDiceKept = 0;
- std::cout << std::to_string(i) + "-" + std::to_string(j) << std::endl;
- std::string diceToKeep;
- if (countChar(keptDice, '1') == 0) {
- firstRoll = rand() % 6 + 1;
- }
- if (countChar(keptDice, '2') == 0) {
- seconRoll = rand() % 6 + 1;
- }
- if (countChar(keptDice, '3') == 0) {
- thirdRoll = rand() % 6 + 1;
- }
- if (countChar(keptDice, '4') == 0) {
- fourtRoll = rand() % 6 + 1;
- }
- if (countChar(keptDice, '5') == 0) {
- fifthRoll = rand() % 6 + 1;
- }
- output += std::to_string(firstRoll);
- output += ", ";
- output += std::to_string(seconRoll);
- output += ", ";
- output += std::to_string(thirdRoll);
- output += ", ";
- output += std::to_string(fourtRoll);
- output += ", ";
- output += std::to_string(fifthRoll);
- output += ".";
- std::cout << output << std::endl;
- if (j < 3) {
- std::cout << "Please input the numerical positions (1 to 5) of the dice you would like to keep." << std::endl;
- std::cout << "If you would not like to keep any, please input a dash." << std::endl;
- std::cin >> diceToKeep;
- bool keepFirst = (countChar(diceToKeep, '1') != 0);
- bool keepSecon = (countChar(diceToKeep, '2') != 0);
- bool keepThird = (countChar(diceToKeep, '3') != 0);
- bool keepFourt = (countChar(diceToKeep, '4') != 0);
- bool keepFifth = (countChar(diceToKeep, '5') != 0);
- if(keepFirst)
- {
- keptDice += "1";
- numDiceKept++;
- }
- if(keepSecon)
- {
- keptDice += "2";
- numDiceKept++;
- }
- if(keepThird)
- {
- keptDice += "3";
- numDiceKept++;
- }
- if(keepFourt)
- {
- keptDice += "4";
- numDiceKept++;
- }
- if(keepFifth)
- {
- keptDice += "5";
- numDiceKept++;
- }
- }
- }
- }
- std::cout << "Pick a section to score in. Sections that you cannot score in will not be displayed." << std::endl;
- if (!upSecOccupied[0]) {
- upSecCanScore[0] = true;
- std::cout << "Aces: One pt per \"1\" rolled." << std::endl;
- }
- if (!upSecOccupied[1]) {
- upSecCanScore[1] = true;
- std::cout << "Twos: Two pts per \"2\" rolled." << std::endl;
- }
- if (!upSecOccupied[2]) {
- upSecCanScore[2] = true;
- std::cout << "Threes: Three pts per \"3\" rolled." << std::endl;
- }
- if (!upSecOccupied[3]) {
- upSecCanScore[3] = true;
- std::cout << "Fours: Four pts per \"4\" rolled." << std::endl;
- }
- if (!upSecOccupied[4]) {
- upSecCanScore[4] = true;
- std::cout << "Fives: Five pts per \"5\" rolled." << std::endl;
- }
- if (!upSecOccupied[5]) {
- upSecCanScore[5] = true;
- std::cout << "Sixes: Six pts per \"6\" rolled." << std::endl;
- }
- if((countChar(output, '1') >= 3 ||
- countChar(output, '2') >= 3 ||
- countChar(output, '3') >= 3 ||
- countChar(output, '4') >= 3 ||
- countChar(output, '5') >= 3 ||
- countChar(output, '6') >= 3) &&
- !loSecOccupied[0])
- {
- loSecCanScore[0] = true;
- std::cout << "Three-of-a-kind: Add total of all dice." << std::endl;
- }
- if((countChar(output, '1') >= 4 ||
- countChar(output, '2') >= 4 ||
- countChar(output, '3') >= 4 ||
- countChar(output, '4') >= 4 ||
- countChar(output, '5') >= 4 ||
- countChar(output, '6') >= 4) &&
- !loSecOccupied[1])
- {
- loSecCanScore[1] = true;
- std::cout << "Four-of-a-kind: Add total of all dice." << std::endl;
- }
- if(!loSecOccupied[2]) {
- if(countChar(output, '1') == 3)
- {
- if (//countChar(output, '1') == 2 ||
- countChar(output, '2') == 2 ||
- countChar(output, '3') == 2 ||
- countChar(output, '4') == 2 ||
- countChar(output, '5') == 2 ||
- countChar(output, '6') == 2) {
- loSecCanScore[2] = true;
- std::cout << "Full-House: 25 pts." << std::endl;
- }
- }
- else if(countChar(output, '2') == 3)
- {
- if(countChar(output, '1') == 2 ||
- //countChar(output, '2') == 2 ||
- countChar(output, '3') == 2 ||
- countChar(output, '4') == 2 ||
- countChar(output, '5') == 2 ||
- countChar(output, '6') == 2)
- {
- loSecCanScore[2] = true;
- std::cout << "Full-House: 25 pts." << std::endl;
- }
- }
- else if(countChar(output, '3') == 3)
- {
- if(countChar(output, '1') == 2 ||
- countChar(output, '2') == 2 ||
- //countChar(output, '3') == 2 ||
- countChar(output, '4') == 2 ||
- countChar(output, '5') == 2 ||
- countChar(output, '6') == 2)
- {
- loSecCanScore[2] = true;
- std::cout << "Full-House: 25 pts." << std::endl;
- }
- }
- else if(countChar(output, '4') == 3)
- {
- if(countChar(output, '1') == 2 ||
- countChar(output, '2') == 2 ||
- countChar(output, '3') == 2 ||
- //countChar(output, '4') == 2 ||
- countChar(output, '5') == 2 ||
- countChar(output, '6') == 2)
- {
- loSecCanScore[2] = true;
- std::cout << "Full-House: 25 pts." << std::endl;
- }
- }
- else if(countChar(output, '5') == 3)
- {
- if(countChar(output, '1') == 2 ||
- countChar(output, '2') == 2 ||
- countChar(output, '3') == 2 ||
- countChar(output, '4') == 2 ||
- //countChar(output, '5') == 2 ||
- countChar(output, '6') == 2)
- {
- loSecCanScore[2] = true;
- std::cout << "Full-House: 25 pts." << std::endl;
- }
- }
- else if (countChar(output, '6') == 3)
- {
- if(countChar(output, '1') == 2 ||
- countChar(output, '2') == 2 ||
- countChar(output, '3') == 2 ||
- countChar(output, '4') == 2 ||
- countChar(output, '5') == 2)
- //countChar(output, '6') == 2)
- {
- loSecCanScore[2] = true;
- std::cout << "Full-House: 25 pts." << std::endl;
- }
- }
- }
- //sm str
- if(!loSecOccupied[3])
- {
- bool oneToFou = countChar(output, '1') >= 1 && countChar(output, '2') >= 1 && countChar(output, '3') >= 1 && countChar(output, '4') >= 1;
- bool twoToFiv = countChar(output, '2') >= 1 && countChar(output, '3') >= 1 && countChar(output, '4') >= 1 && countChar(output, '5') >= 1;
- bool thrToSix = countChar(output, '3') >= 1 && countChar(output, '4') >= 1 && countChar(output, '5') >= 1 && countChar(output, '6') >= 1;
- if(oneToFou || twoToFiv || thrToSix)
- {
- loSecCanScore[3] = true;
- std::cout << "Small-Straight: 30 pts." << std::endl;
- }
- }
- //lg str
- if(!loSecOccupied[4])
- {
- bool oneToFiv = countChar(output, '1') == 1 && countChar(output, '2') == 1 && countChar(output, '3') == 1 && countChar(output, '4') == 1 && countChar(output, '5') == 1;
- bool twoToSix = countChar(output, '2') == 1 && countChar(output, '3') == 1 && countChar(output, '4') == 1 && countChar(output, '5') == 1 && countChar(output, '6') == 1;
- if(oneToFiv || twoToSix)
- {
- loSecCanScore[4] = true;
- std::cout << "Large-Straight: 40 pts." << std::endl;
- }
- }
- if(countChar(output, '1') == 5 ||
- countChar(output, '2') == 5 ||
- countChar(output, '3') == 5 ||
- countChar(output, '4') == 5 ||
- countChar(output, '5') == 5 ||
- countChar(output, '6') == 5)
- {
- if(loSecOccupied[5])
- {
- //bonus yahtzee
- }
- else
- {
- loSecCanScore[5] = true;
- std::cout << "Yahtzee: 50 pts." << std::endl;
- }
- }
- //chance
- if(!loSecOccupied[6])
- {
- loSecCanScore[6] = true;
- std::cout << "Chance: Score total of all five dice." << std::endl;
- }
- //pick their section to score
- if((!upSecCanScore[0] && !upSecCanScore[1] && !upSecCanScore[2] && !upSecCanScore[3] && !upSecCanScore[4] && !upSecCanScore[5]) &&
- (!loSecCanScore[0] && !loSecCanScore[1] && !loSecCanScore[2] && !loSecCanScore[3] && !loSecCanScore[4] && !loSecCanScore[5] && !loSecCanScore[6]))
- {
- //check bonus yahtzees
- //pick one to blank out
- std::string blankOutput = "Choose one of the following to blank out for zero points:";
- std::string blankInput;
- if(!upSecOccupied[0])
- {
- blankOutput += "Aces, ";
- }
- if(!upSecOccupied[1])
- {
- blankOutput += "Twos, ";
- }
- if(!upSecOccupied[2])
- {
- blankOutput += "Threes, ";
- }
- if(!upSecOccupied[3])
- {
- blankOutput += "Fours, ";
- }
- if(!upSecOccupied[4])
- {
- blankOutput += "Fives, ";
- }
- if(!upSecOccupied[5])
- {
- blankOutput += "Sixes, ";
- }
- if(!loSecOccupied[0])
- {
- blankOutput += "Three-of-a-Kind, ";
- }
- if(!loSecOccupied[1])
- {
- blankOutput += "Four-of-a-Kind, ";
- }
- if(!loSecOccupied[2])
- {
- blankOutput += "Full House, ";
- }
- if(!loSecOccupied[3])
- {
- blankOutput += "Small-Straight, ";
- }
- if(!loSecOccupied[4])
- {
- blankOutput += "Large-Straight, ";
- }
- if(!loSecOccupied[5])
- {
- blankOutput += "Yahtzee, ";
- }
- if(!loSecOccupied[6])
- {
- blankOutput += "Chance";
- }
- std::cout << blankOutput << std::endl;
- std::cin >> blankInput;
- bool validChoice = !((((upSecCanScore[0] && scoreSection == "Aces") ||
- (upSecCanScore[1] && scoreSection == "Twos") ||
- (upSecCanScore[2] && scoreSection == "Threes") ||
- (upSecCanScore[3] && scoreSection == "Fours") ||
- (upSecCanScore[4] && scoreSection == "Fives") ||
- (upSecCanScore[5] && scoreSection == "Sixes")) ||
- ((loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
- (loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
- (loSecCanScore[2] && scoreSection == "Full-House") ||
- (loSecCanScore[3] && scoreSection == "Small-Straight") ||
- (loSecCanScore[4] && scoreSection == "Large-Straight") ||
- (loSecCanScore[5] && scoreSection == "Yahtzee") ||
- (loSecCanScore[6] && scoreSection == "Chance"))) ||
- (scoreSection != "Aces" &&
- scoreSection != "Twos" &&
- scoreSection != "Threes" &&
- scoreSection != "Fours" &&
- scoreSection != "Fives" &&
- scoreSection != "Sixes" &&
- scoreSection != "Three-of-a-Kind" &&
- scoreSection != "Four-of-a-Kind" &&
- scoreSection != "Full-House" &&
- scoreSection != "Small-Straight" &&
- scoreSection != "Large-Straight" &&
- scoreSection != "Yahtzee" &&
- scoreSection != "Chance"));
- while(!validChoice)
- {
- std::cout << "Your choice was invalid. Try again." << std::endl;
- blankOutput = "Choose one of the following to blank out for zero points: ";
- if(!upSecOccupied[0])
- {
- blankOutput += "Aces, ";
- }
- if(!upSecOccupied[1])
- {
- blankOutput += "Twos, ";
- }
- if(!upSecOccupied[2])
- {
- blankOutput += "Threes, ";
- }
- if(!upSecOccupied[3])
- {
- blankOutput += "Fours, ";
- }
- if(!upSecOccupied[4])
- {
- blankOutput += "Fives, ";
- }
- if(!upSecOccupied[5])
- {
- blankOutput += "Sixes, ";
- }
- if(!loSecOccupied[0])
- {
- blankOutput += "Three-of-a-Kind, ";
- }
- if(!loSecOccupied[1])
- {
- blankOutput += "Four-of-a-Kind, ";
- }
- if(!loSecOccupied[2])
- {
- blankOutput += "Full House, ";
- }
- if(!loSecOccupied[3])
- {
- blankOutput += "Small-Straight, ";
- }
- if(!loSecOccupied[4])
- {
- blankOutput += "Large-Straight, ";
- }
- if(!loSecOccupied[5])
- {
- blankOutput += "Yahtzee, ";
- }
- if(!loSecOccupied[6])
- {
- blankOutput += "Chance";
- }
- std::cout << blankOutput << std::endl;
- std::cin >> blankInput;
- validChoice = !((((upSecCanScore[0] && scoreSection == "Aces") ||
- (upSecCanScore[1] && scoreSection == "Twos") ||
- (upSecCanScore[2] && scoreSection == "Threes") ||
- (upSecCanScore[3] && scoreSection == "Fours") ||
- (upSecCanScore[4] && scoreSection == "Fives") ||
- (upSecCanScore[5] && scoreSection == "Sixes")) ||
- ((loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
- (loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
- (loSecCanScore[2] && scoreSection == "Full-House") ||
- (loSecCanScore[3] && scoreSection == "Small-Straight") ||
- (loSecCanScore[4] && scoreSection == "Large-Straight") ||
- (loSecCanScore[5] && scoreSection == "Yahtzee") ||
- (loSecCanScore[6] && scoreSection == "Chance"))) ||
- (scoreSection != "Aces" &&
- scoreSection != "Twos" &&
- scoreSection != "Threes" &&
- scoreSection != "Fours" &&
- scoreSection != "Fives" &&
- scoreSection != "Sixes" &&
- scoreSection != "Three-of-a-Kind" &&
- scoreSection != "Four-of-a-Kind" &&
- scoreSection != "Full-House" &&
- scoreSection != "Small-Straight" &&
- scoreSection != "Large-Straight" &&
- scoreSection != "Yahtzee" &&
- scoreSection != "Chance"));
- }
- std::cout << blankInput << std::endl;
- if(blankInput == "Aces")
- {
- upSecOccupied[0] = true;
- upSecScore[0] = 0;
- }
- if(blankInput == "Twos")
- {
- upSecOccupied[1] = true;
- upSecScore[1] = 0;
- }
- if(blankInput == "Thres")
- {
- upSecOccupied[2] = true;
- upSecScore[2] = 0;
- }
- if(blankInput == "Fours")
- {
- upSecOccupied[3] = true;
- upSecScore[3] = 0;
- }
- if(blankInput == "Fives")
- {
- upSecOccupied[4] = true;
- upSecScore[4] = 0;
- }
- if(blankInput == "Sixes")
- {
- upSecOccupied[5] = true;
- upSecScore[5] = 0;
- }
- }
- else
- {
- std::cout << "Choose one of the above options, without spaces." << std::endl;
- std::cin >> scoreSection;
- //This works, don't look at it for too long.
- bool validChoice = !((((!upSecCanScore[0] && scoreSection == "Aces") ||
- (!upSecCanScore[1] && scoreSection == "Twos") ||
- (!upSecCanScore[2] && scoreSection == "Threes") ||
- (!upSecCanScore[3] && scoreSection == "Fours") ||
- (!upSecCanScore[4] && scoreSection == "Fives") ||
- (!upSecCanScore[5] && scoreSection == "Sixes")) ||
- ((!loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
- (!loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
- (!loSecCanScore[2] && scoreSection == "Full-House") ||
- (!loSecCanScore[3] && scoreSection == "Small-Straight") ||
- (!loSecCanScore[4] && scoreSection == "Large-Straight") ||
- (!loSecCanScore[5] && scoreSection == "Yahtzee") ||
- (!loSecCanScore[6] && scoreSection == "Chance"))) ||
- (scoreSection != "Aces" &&
- scoreSection != "Twos" &&
- scoreSection != "Threes" &&
- scoreSection != "Fours" &&
- scoreSection != "Fives" &&
- scoreSection != "Sixes" &&
- scoreSection != "Three-of-a-Kind" &&
- scoreSection != "Four-of-a-Kind" &&
- scoreSection != "Full-House" &&
- scoreSection != "Small-Straight" &&
- scoreSection != "Large-Straight" &&
- scoreSection != "Yahtzee" &&
- scoreSection != "Chance"));
- while(!validChoice)
- {
- std::string invalidOutput = "Your choice was invalid. Please input one of the following (case-sensitive, no spaces): ";
- if(upSecCanScore[0])
- {
- invalidOutput += "Aces, ";
- }
- if(upSecCanScore[1])
- {
- invalidOutput += "Twos, ";
- }
- if(upSecCanScore[2])
- {
- invalidOutput += "Threes, ";
- }
- if(upSecCanScore[3])
- {
- invalidOutput += "Fours, ";
- }
- if(upSecCanScore[4])
- {
- invalidOutput += "Fives, ";
- }
- if(upSecCanScore[5])
- {
- invalidOutput += "Sixes, ";
- }
- if(loSecCanScore[0])
- {
- invalidOutput += "Three-of-a-Kind, ";
- }
- if(loSecCanScore[1])
- {
- invalidOutput += "Four-of-a-Kind, ";
- }
- if(loSecCanScore[2])
- {
- invalidOutput += "Full-House, ";
- }
- if(loSecCanScore[3])
- {
- invalidOutput += "Small-Straight, ";
- }
- if(loSecCanScore[4])
- {
- invalidOutput += "Large-Straight, ";
- }
- if(loSecCanScore[5])
- {
- invalidOutput += "Yahtzee, ";
- }
- if(loSecCanScore[6])
- {
- invalidOutput += "Chance";
- }
- std::cin >> scoreSection;
- validChoice = ((((!upSecCanScore[0] && scoreSection == "Aces") ||
- (!upSecCanScore[1] && scoreSection == "Twos") ||
- (!upSecCanScore[2] && scoreSection == "Threes") ||
- (!upSecCanScore[3] && scoreSection == "Fours") ||
- (!upSecCanScore[4] && scoreSection == "Fives") ||
- (!upSecCanScore[5] && scoreSection == "Sixes")) ||
- ((!loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
- (!loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
- (!loSecCanScore[2] && scoreSection == "FullHouse") ||
- (!loSecCanScore[3] && scoreSection == "SmallStraight") ||
- (!loSecCanScore[4] && scoreSection == "LargeStraight") ||
- (!loSecCanScore[5] && scoreSection == "Yahtzee") ||
- (!loSecCanScore[6] && scoreSection == "Chance"))) ||
- (scoreSection != "Aces" &&
- scoreSection != "Twos" &&
- scoreSection != "Threes" &&
- scoreSection != "Fours" &&
- scoreSection != "Fives" &&
- scoreSection != "Sixes" &&
- scoreSection != "Three-of-a-Kind" &&
- scoreSection != "Four-of-a-Kind" &&
- scoreSection != "Full-House" &&
- scoreSection != "Small-Straight" &&
- scoreSection != "Large-Straight" &&
- scoreSection != "Yahtzee" &&
- scoreSection != "Chance"));
- }
- //score
- std::string bonusScore;
- if(scoreSection == "Aces")
- {
- //count 1s and score
- upSecScore[0] = countChar(output, '1');
- std::cout << "You scored " + std::to_string(upSecScore[0]) + " point(s) in the Aces section." << std::endl;
- if(countChar(output, '1') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
- {
- //bonus yahtzee!
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- while(bonusScore != "Y" && bonusScore != "N")
- {
- std::cout << "SPEAK CLEARLY." << std::endl;
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- }
- if(bonusScore == "N")
- {
- std::cout << "You're crazy, but okay." << std::endl;
- }
- else
- {
- //score the bonus later
- yahtzeeCount++;
- }
- }
- }
- if(scoreSection == "Twos")
- {
- //count 2s and score
- upSecScore[1] = countChar(output, '2') * 2;
- std::cout << "You scored " + std::to_string(upSecScore[1]) + " point(s) in the Twos section." << std::endl;
- if(countChar(output, '2') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
- {
- //bonus yahtzee!
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- while(bonusScore != "Y" && bonusScore != "N")
- {
- std::cout << "SPEAK CLEARLY." << std::endl;
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- }
- if(bonusScore == "N")
- {
- std::cout << "You're crazy, but okay." << std::endl;
- }
- else
- {
- //score the bonus later
- yahtzeeCount++;
- }
- }
- }
- if(scoreSection == "Threes")
- {
- //count 3s and score
- upSecScore[2] = countChar(output, '3') * 3;
- std::cout << "You scored " + std::to_string(upSecScore[2]) + " point(s) in the Threes section." << std::endl;
- if(countChar(output, '3') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
- {
- //bonus yahtzee!
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- while(bonusScore != "Y" && bonusScore != "N")
- {
- std::cout << "SPEAK CLEARLY." << std::endl;
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- }
- if(bonusScore == "N")
- {
- std::cout << "You're crazy, but okay." << std::endl;
- }
- else
- {
- //score the bonus later
- yahtzeeCount++;
- }
- }
- }
- if(scoreSection == "Fours")
- {
- //count 4s and score
- upSecScore[3] = countChar(output, '4') * 4;
- std::cout << "You scored " + std::to_string(upSecScore[3]) + " point(s) in the Fours section." << std::endl;
- if(countChar(output, '4') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
- {
- //bonus yahtzee!
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- while(bonusScore != "Y" && bonusScore != "N")
- {
- std::cout << "SPEAK CLEARLY." << std::endl;
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- }
- if(bonusScore == "N")
- {
- std::cout << "You're crazy, but okay." << std::endl;
- }
- else
- {
- //score the bonus later
- yahtzeeCount++;
- }
- }
- }
- if(scoreSection == "Fives")
- {
- //count 5s and score
- upSecScore[4] = countChar(output, '5') * 5;
- std::cout << "You scored " + std::to_string(upSecScore[4]) + " point(s) in the Aces section." << std::endl;
- if(countChar(output, '5') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
- {
- //bonus yahtzee!
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- while(bonusScore != "Y" && bonusScore != "N")
- {
- std::cout << "SPEAK CLEARLY." << std::endl;
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- }
- if(bonusScore == "N")
- {
- std::cout << "You're crazy, but okay." << std::endl;
- }
- else
- {
- //score the bonus later
- yahtzeeCount++;
- }
- }
- }
- if(scoreSection == "Sixes")
- {
- //count 6s and score
- upSecScore[5] = countChar(output, '6') * 6;
- std::cout << "You scored " + std::to_string(upSecScore[5]) + " point(s) in the Aces section." << std::endl;
- if(countChar(output, '6') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
- {
- //bonus yahtzee!
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- while(bonusScore != "Y" && bonusScore != "N")
- {
- std::cout << "SPEAK CLEARLY." << std::endl;
- std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
- std::cin >> bonusScore;
- }
- if(bonusScore == "N")
- {
- std::cout << "You're crazy, but okay." << std::endl;
- }
- else
- {
- //score the bonus later
- yahtzeeCount++;
- }
- }
- }
- if(scoreSection == "Three-of-a-Kind")
- {
- //sum all dice
- int oneScore = countChar(output, '1') * 1;
- int twoScore = countChar(output, '2') * 2;
- int thrScore = countChar(output, '3') * 3;
- int fouScore = countChar(output, '4') * 4; //fou score and seven years ago...
- int fivScore = countChar(output, '5') * 5;
- int sixScore = countChar(output, '6') * 6;
- loSecScore[0] = oneScore + twoScore + thrScore + fouScore + fivScore + sixScore;
- std::cout << "You scored " + std::to_string(loSecScore[0]) + " point(s) in the Three-of-a-Kind section." << std::endl;
- }
- if(scoreSection == "Four-of-a-Kind")
- {
- //sum all dice
- int oneScore = countChar(output, '1') * 1;
- int twoScore = countChar(output, '2') * 2;
- int thrScore = countChar(output, '3') * 3;
- int fouScore = countChar(output, '4') * 4; //fou score and seven years ago...
- int fivScore = countChar(output, '5') * 5;
- int sixScore = countChar(output, '6') * 6;
- loSecScore[1] = oneScore + twoScore + thrScore + fouScore + fivScore + sixScore;
- std::cout << "You scored " + std::to_string(loSecScore[1]) + " point(s) in the Four-of-a-Kind section." << std::endl;
- }
- if(scoreSection == "Full-House")
- {
- //25
- loSecScore[2] = 25;
- std::cout << "You scored " + std::to_string(loSecScore[2]) + " point(s) in the Full-House section." << std::endl;
- }
- if(scoreSection == "Small-Straight")
- {
- //30
- loSecScore[3] = 30;
- std::cout << "You scored " + std::to_string(loSecScore[3]) + " point(s) in the Small-Straight section." << std::endl;
- }
- if(scoreSection == "Large-Straight")
- {
- //40
- loSecScore[4] = 40;
- std::cout << "You scored " + std::to_string(loSecScore[4]) + " point(s) in the Large-Straight section." << std::endl;
- }
- if(scoreSection == "Yahtzee")
- {
- //50
- loSecScore[5] = 50;
- std::cout << "You scored " + std::to_string(loSecScore[5]) + " point(s) in the Yahtzee section." << std::endl;
- }
- if(scoreSection == "Chance")
- {
- //sum all dice
- int oneScore = countChar(output, '1') * 1;
- int twoScore = countChar(output, '2') * 2;
- int thrScore = countChar(output, '3') * 3;
- int fouScore = countChar(output, '4') * 4; //fou score and seven years ago...
- int fivScore = countChar(output, '5') * 5;
- int sixScore = countChar(output, '6') * 6;
- loSecScore[6] = oneScore + twoScore + thrScore + fouScore + fivScore + sixScore;
- std::cout << "You scored " + std::to_string(loSecScore[6]) + " point(s) in the Chance section." << std::endl;
- }
- //print out scores
- } //ends scoring section if/else statement
- //print out scorecard
- std::cout << "SCORECARD" << std::endl;
- std::cout << "Aces: " + std::to_string(upSecScore[0]) << std::endl;
- std::cout << "Twos: " + std::to_string(upSecScore[1]) << std::endl;
- std::cout << "Threes: " + std::to_string(upSecScore[2]) << std::endl;
- std::cout << "Fours: " + std::to_string(upSecScore[3]) << std::endl;
- std::cout << "Fives: " + std::to_string(upSecScore[4]) << std::endl;
- std::cout << "Sixes: " + std::to_string(upSecScore[5]) << std::endl;
- std::cout << "Three-of-a-Kind: " + std::to_string(loSecScore[0]) << std::endl;
- std::cout << "Four-of-a-Kind: " + std::to_string(loSecScore[1]) << std::endl;
- std::cout << "Full-House: " + std::to_string(loSecScore[2]) << std::endl;
- std::cout << "Small-Straight: " + std::to_string(loSecScore[3]) << std::endl;
- std::cout << "Large-Straight: " + std::to_string(loSecScore[4]) << std::endl;
- if(yahtzeeCount < 2)
- {
- std::cout << "Yahtzee: " + std::to_string(yahtzeeCount * 50) << std::endl;
- std::cout << "Bonus Yahtzees: 0" << std::endl;
- }
- else
- {
- std::cout << "Yahtzee: 50" << std::endl;
- std::cout << "Bonus Yahtzees: " + std::to_string((yahtzeeCount - 1) * 100) << std::endl;
- }
- std::cout << "Chance: " + std::to_string(loSecScore[6]) << std::endl;
- } //ends turn for loop
- return 0;
- } //ends main
Advertisement
Add Comment
Please, Sign In to add comment