Code: Show/Hide #include <iostream>
using namespace std; int main() { int throw1, throw2, throw3; int score; cout << "Please enter the score for the first throw:\n"; cin >> throw1; if ( throw1 > 10 ) { cout << "You can't knock down more than 10 pins in one throw.\n"; system("pause"); return 1; } cout << "Please enter the score for the second throw:\n"; cin >> throw2; if ( throw1 > 10 ) { cout << "You can't knock down more than 10 pins in one throw.\n"; system("pause"); return 1; } else if ( throw1 != 10 && throw1 + throw2 > 10 ) { cout << "You can't knock down more than 10 pins in one frame.\n"; system("pause"); return 1; } if ( throw1 == 10 || throw1 + throw2 == 10 ) { cout << "Please enter the score for the third throw:\n"; cin >> throw3; if ( throw3 > 10 ) { cout << "You can't knock down more than 10 pins in one throw.\n"; system("pause"); return 1; } else if ( throw1 == 10 && throw2 != 10 && throw2 + throw3 > 10 ) { cout << "You can't knock down more than 10 pins in one frame.\n"; system("pause"); return 1; } } if ( throw1 == 10 || (throw1 + throw2) == 10 ) { score = throw1 + throw2 + throw3; cout << "Your score is: " << score << endl; } else { score = throw1 + throw2; cout << "Your score is: " << score << endl; } system("pause"); return 1; } // end of main() |
Code: Show/Hide void func()
{ } |
Code: Show/Hide int a;
char buf[256]; /* set initial values */ a = 0; buf[0] = 0; scanf("%d %255s", &a, buf); |
Smong wrote: |
It also looks like they are teaching you C++, either way I also prefer to use printf and you can use scanf to read input: (as opposed to cin/cout) |
Code: Show/Hide while (1)
{ cout << "Enter value: "; cin >> value; if ((value > too_small && value < too_big) || value == special_value) break; cout << "Value is invalid, please try again.\n"; } |
Code: Show/Hide cout << "Enter value: ";
cin >> value; while (value < too_small || value > too_big || value != special_value) { cout << "Value is invalid, please try again.\n"; cout << "Enter value: "; cin >> value; } |
CypherJF wrote: |
if the frame doesn't include a spare or a strike then the total for the frame is that of the 2 throws.
if the strike occurs on the first throw then it counts as 10 + the next 2 throws. if the throw results in a spare then it is 10 + the next throw. if on the last frame (10th) if you get a strike 2 you get 2 more throws, if you get a spare you get 1 more and you calculate from there. thats if i can recall this correctly.. haven't done manual bowling calculation in years. also don't forget about fouls, i think it counts as a miss? |