Advertisement
JustACodingStudent

Bowl O Rama (School Project)

Mar 24th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int score, pins, frame, fnum, turkey, gamenum;
  8.     double avgscore;
  9.     char retry;
  10.     string name;
  11.     //Starts score as 0, and the same for the turkey count. First frame and game number are defined.
  12.     score = 0;
  13.     turkey = 0;
  14.     fnum = 1;
  15.     gamenum = 1;
  16.     // Allows a user to enter their nickname. If the name is greater than 4 characters, it cuts it down to the appropriate length.
  17.     cout << "Enter your nickname (One word): ";
  18.     cin >> name;
  19.  
  20.     if(name.length() > 4){
  21.         name = name.substr(0, 4);
  22.     }
  23.     system("cls");
  24.     for(frame = 10; frame >= 1; frame--)
  25.     {
  26.         cout << "-----------------------------------\n" << endl;
  27.         cout << "Frame Number: " << fnum << endl;
  28.         //User enters pins knocked down.
  29.         cout << "Enter amount of pins knocked down: " << endl;
  30.         cin >> pins;
  31.         //Error checks if pins are greater than 10.
  32.  
  33.         while(pins > 10)
  34.         {
  35.             cout << "There are only 10 pins. Please enter your pins knocked down: ";
  36.             cin >> pins;
  37.         }
  38.         //If the user hits 10 pins, it begins stacking up the turkey count.
  39.  
  40.         if(pins == 10){
  41.             turkey += 1;
  42.         }
  43.         //Resets the turkey count once a count other than 10 is inputted.
  44.         else{
  45.             turkey = 0;
  46.         }
  47.         //Once the turkey count is up to three, it displays that the user has scored a turkey. Afterwards, It resets the turkey count.
  48.  
  49.         if(turkey == 3){
  50.             cout << "\nT" << endl;
  51.             cout << "U" << endl;
  52.             cout << "R" << endl;
  53.             cout << "K" << endl;
  54.             cout << "E" << endl;
  55.             cout << "Y" << endl;
  56.             turkey = 0;
  57.         }
  58.         //Adds the amount of pins to the score.
  59.  
  60.         score += pins;
  61.         fnum += 1;
  62.         cout << "\n-----------------------------------\n" << endl;
  63.     }
  64.     avgscore = score / gamenum;
  65.     cout << "Would you like to play another game? (y/n)" << endl;
  66.     cin >> retry;
  67.  
  68.     //Repeats the program.
  69.  
  70.     do
  71.     {
  72.     turkey = 0;
  73.     fnum = 1;
  74.     gamenum += 1;
  75.     system("cls");
  76.     for(frame = 10; frame >= 1; frame--)
  77.     {
  78.         cout << "Frame Number: " << fnum << endl;
  79.         cout << "Enter amount of pins knocked down: " << endl;
  80.         cin >> pins;
  81.  
  82.         while(pins > 10)
  83.         {
  84.             cout << "There are only 10 pins. Please enter your pins knocked down: ";
  85.             cin >> pins;
  86.         }
  87.  
  88.         if(pins == 10){
  89.             turkey += 1;
  90.         }
  91.         else{
  92.             turkey = 0;
  93.         }
  94.  
  95.         if(turkey == 3){
  96.             cout << "\nT" << endl;
  97.             cout << "U" << endl;
  98.             cout << "R" << endl;
  99.             cout << "K" << endl;
  100.             cout << "E" << endl;
  101.             cout << "Y" << endl;
  102.             turkey = 0;
  103.         }
  104.  
  105.         score += pins;
  106.         fnum += 1;
  107.         cout << "\n-----------------------------------\n" << endl;
  108.     }
  109.     avgscore = score / gamenum;
  110.     cout << "Would you like to play another game? (y/n)" << endl;
  111.     cin >> retry;
  112.     }while(retry == 'y');
  113.  
  114.     //Clears the screen and displays the score + the appropriate endgame message.
  115.  
  116.     system("cls");
  117.     cout << "Your score is: " << avgscore;
  118.  
  119.     if(avgscore > 80){
  120.         cout << "\nYou need to play professionally now! Great job " << name << "!";
  121.     }
  122.     else if(avgscore > 50){
  123.         cout << "\nNot too shabby. Keep it up " << name << "!";
  124.     }
  125.     else if(avgscore < 50){
  126.         cout << "\nPractice makes perfect " << name << "!";
  127.     }
  128.     //End of program.
  129.     int x;
  130.     cin>>x;
  131.     return(0);
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement