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
|
/*
This is a program that lets the user enter your scores for bowling. If you enter a
invalid score it will tell you what one is wrong and why then tell you to try again.
*/
#include <iostream>
using namespace std;
void GiveDirections();
void YourScores(int & throwOne,int & throwTwo,int & throwThree);
bool FindErrors(int throwOne,int throwTwo,int throwThree);
void TellScore(int throwOne,int throwTwo,int throwThree);
int main (){
GiveDirections(); // These functions
int throwOne, // just tells the user
throwTwo, // to enter their scores
throwThree; // and checks them to see
YourScores(throwOne,throwTwo,throwThree); // if they are valid
FindErrors(throwOne,throwTwo,throwThree); // then prints your score
TellScore(throwOne,throwTwo,throwThree); // if it is valid
return 0;
}
void GiveDirections(){ // Gives the user the directions
cout << "Today were going bowling! Your going to be throwing three balls. "
<< "You can't throw more than 10 or less than 0 on any of them. "
<< "If you throw a strike on the first one and the second one, your score is 20 plus whatever you get on the third one "
<< "but if you don't get a strike on the first one, you won't be able to get more than 20. Can't score more than 30 total.\n";
cout << "Grab your balls, we're going bowling!!!\n\n";
return;
}
void YourScores(int & throwOne,int & throwTwo,int & throwThree){
string question = "Enter your score: ";
cout << question; // Prompts the user to enter their score
cin >> throwOne;
cout << question; // Prompts the user to enter their score
cin >> throwTwo;
cout << question; // Prompts the user to enter their score
cin >> throwThree;
return;
}
bool FindErrors(int throwOne,int throwTwo,int throwThree){ // All these "if" statements find out if the scores are valid or not
bool result = false; // Starts out as a false statements
if (throwOne > 10){
cout << "Throw of " << throwOne << " is invalid because you can't score more than 10 on one throw!\n";
}else if (throwOne < 0){
cout << "Throw of " << throwOne << " is invalid because you can't score less than 0!\n";
}else if (throwTwo > 10){
cout << "Throw of " << throwTwo << " is invalid because you can't score more than 10 on one throw!\n";
}else if (throwTwo < 0){
cout << "Throw of " << throwTwo << " is invalid because you can't score less than 0!\n";
}else if (throwThree > 10){
cout << "Throw of " << throwThree << " is invalid because you can't score more than 10 on one throw!\n";
}else if (throwThree < 0){
cout << "Throw of " << throwThree << " is invalid because you can't score less than 0!\n";
}else if (throwOne == 10 && throwTwo < 10 && throwThree + throwTwo > 10){
cout << "Throw of " << throwThree << " is invalid because you can't score more than 20 after getting a strike on the first throw!\n";
}else if (throwOne < 10 && throwOne > 0 && throwTwo == 10){
cout << "Throw of " << throwTwo << " is invalid because you can't get a strike on the second throw after knocking some down in the first throw!\n";
}
else if (throwOne + throwTwo > 10 && throwOne != 10){
cout << "Throw of " << throwTwo << " is invalid because you can't score more than 10 on the first frame\n";
}else{
result = true; // If any of these are true, it returns true, if not, stays false
}
return result;
}
void TellScore(int throwOne, int throwTwo, int throwThree){
int score = throwOne + throwTwo + throwThree;
bool result;{
if (throwOne + throwTwo < 10 && throwThree != 0){ // If you don't get a strike or spare on the first two throws, the third doesn't count.
cout << "Your score is " << throwOne + throwTwo << endl; // Tells the score only if
}else if (result == true) // the scores are valid
cout << "Your score is " << score << '!' << endl;
else{ // If not, tells you
cout << "Try Again!!!\n"; // to try again!!!
}
}
return;
}
|