Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int score, pins, frame, fnum, turkey, gamenum;
- double avgscore;
- char retry;
- string name;
- //Starts score as 0, and the same for the turkey count. First frame and game number are defined.
- score = 0;
- turkey = 0;
- fnum = 1;
- gamenum = 1;
- // Allows a user to enter their nickname. If the name is greater than 4 characters, it cuts it down to the appropriate length.
- cout << "Enter your nickname (One word): ";
- cin >> name;
- if(name.length() > 4){
- name = name.substr(0, 4);
- }
- system("cls");
- for(frame = 10; frame >= 1; frame--)
- {
- cout << "-----------------------------------\n" << endl;
- cout << "Frame Number: " << fnum << endl;
- //User enters pins knocked down.
- cout << "Enter amount of pins knocked down: " << endl;
- cin >> pins;
- //Error checks if pins are greater than 10.
- while(pins > 10)
- {
- cout << "There are only 10 pins. Please enter your pins knocked down: ";
- cin >> pins;
- }
- //If the user hits 10 pins, it begins stacking up the turkey count.
- if(pins == 10){
- turkey += 1;
- }
- //Resets the turkey count once a count other than 10 is inputted.
- else{
- turkey = 0;
- }
- //Once the turkey count is up to three, it displays that the user has scored a turkey. Afterwards, It resets the turkey count.
- if(turkey == 3){
- cout << "\nT" << endl;
- cout << "U" << endl;
- cout << "R" << endl;
- cout << "K" << endl;
- cout << "E" << endl;
- cout << "Y" << endl;
- turkey = 0;
- }
- //Adds the amount of pins to the score.
- score += pins;
- fnum += 1;
- cout << "\n-----------------------------------\n" << endl;
- }
- avgscore = score / gamenum;
- cout << "Would you like to play another game? (y/n)" << endl;
- cin >> retry;
- //Repeats the program.
- do
- {
- turkey = 0;
- fnum = 1;
- gamenum += 1;
- system("cls");
- for(frame = 10; frame >= 1; frame--)
- {
- cout << "Frame Number: " << fnum << endl;
- cout << "Enter amount of pins knocked down: " << endl;
- cin >> pins;
- while(pins > 10)
- {
- cout << "There are only 10 pins. Please enter your pins knocked down: ";
- cin >> pins;
- }
- if(pins == 10){
- turkey += 1;
- }
- else{
- turkey = 0;
- }
- if(turkey == 3){
- cout << "\nT" << endl;
- cout << "U" << endl;
- cout << "R" << endl;
- cout << "K" << endl;
- cout << "E" << endl;
- cout << "Y" << endl;
- turkey = 0;
- }
- score += pins;
- fnum += 1;
- cout << "\n-----------------------------------\n" << endl;
- }
- avgscore = score / gamenum;
- cout << "Would you like to play another game? (y/n)" << endl;
- cin >> retry;
- }while(retry == 'y');
- //Clears the screen and displays the score + the appropriate endgame message.
- system("cls");
- cout << "Your score is: " << avgscore;
- if(avgscore > 80){
- cout << "\nYou need to play professionally now! Great job " << name << "!";
- }
- else if(avgscore > 50){
- cout << "\nNot too shabby. Keep it up " << name << "!";
- }
- else if(avgscore < 50){
- cout << "\nPractice makes perfect " << name << "!";
- }
- //End of program.
- int x;
- cin>>x;
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement