Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ok I designed a football program and there are 3 things wrong with the code. The

ID: 3622568 • Letter: O

Question

Ok I designed a football program and there are 3 things wrong with the code. The program compiles and runs but these are the additions I need to make
1. the penalties are not quite right. A 1st down could happen for a 4th down penalty on the first one you look to see if the down >4 first then look at the yards by then it is too late
2. The extra points are not to default to 0if they are invalid it should keep asking until they enter a valid value
3. The program does not repeat fully if the user selects to run it again.

Heres the code:
#include <iostream>
#include <string>

using namespace std;

int main() {
bool anotherGame = true, gameIsOver = false;
bool homeHasBall;
string home, visitor, qrtrStr, hasBallStr;
char receiving, choice;
int quarter, homeScore, visitorScore, down, yardsTo1stDown;

cout << " 2010 Football Playoff Referee's Assistant ";
while(anotherGame == true) {
cout << "What is the home team Mascot name? ";
cin >> home;
cout << "What is the visiting team Mascot name? ";
cin >> visitor;
cout << "Which Team has elected to receive the ball (H\V)? ";
cin >> receiving;
cout << endl;
if (tolower(receiving) == 'h')
homeHasBall = true;
else
homeHasBall = false;

cout << "EventCode Description EventCode Description ";
cout << "y Yardage made on play t Ball turned over ";
cout << "f Field Goal q Quarter is over ";
cout << "g Goal (touchdown) p Penalty ";
cout << "s Safety C Game Canceled ";

quarter = 1;
homeScore = 0;
visitorScore = 0;
yardsTo1stDown = 10;
down = 1;
while (gameIsOver == false) {
if (quarter == 1)
qrtrStr = "1st";
else if (quarter == 2)
qrtrStr = "2nd";
else if (quarter == 3)
qrtrStr = "3rd";
else
qrtrStr = "4th";
if (homeHasBall == true)
hasBallStr = "H [" + home + "]";
else
hasBallStr = "V [" + visitor + "]";
cout << "Scoreboard: " << qrtrStr << " Quarter Ball Possession " << hasBallStr << endl;
cout << "Home [" << home << "] " << homeScore << " Visitors [" << visitor << "] " << visitorScore << " Down " << down << " " << yardsTo1stDown << " Yards to first down" << endl;
cout << "What event? ";
cin >> choice;

choice = tolower(choice);

if (choice == 'y') {
int yards;
cout << "How many yards gained? ";
cin >> yards;
yardsTo1stDown -= yards;
if (yardsTo1stDown <= 0) {
yardsTo1stDown = 10;
down = 1;
} else {
down++;
}
if (down > 4) {
yardsTo1stDown = 10;
down = 1;
homeHasBall = !homeHasBall;
}
} else if (choice == 'f') {
if (homeHasBall)
homeScore += 3;
else
visitorScore += 3;
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 'g') {
int extra;
cout << "How many extra points? ";
cin >> extra;
if (extra > 2 || extra < 0) {
cout << "Invalid number of extra points. Defaulting to 0.";
extra = 0;
}
if (homeHasBall)
homeScore += 6 + extra;
else
visitorScore += 6 + extra;
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 's') {
if (homeHasBall)
visitorScore += 2;
else
homeScore += 2;
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 't') {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 'q') {
quarter++;
if (quarter > 4)
gameIsOver = true;
else if (quarter == 3) {
cout << "End of 1st Half"<<" Home [" << home << "] " << homeScore << " Visitors [" << visitor << "] " << visitorScore << endl<<endl;
if (tolower(receiving) == 'h')
homeHasBall = false;
else
homeHasBall = true;
yardsTo1stDown = 10;
down = 1;
}
} else if (choice == 'p') {
char team, repeat;
int penalty;
cout << "Which team (H/V)? ";
cin >> team;
cout << "Repeat of down (Y/N)? ";
cin >> repeat;
cout << "Yards penalized? ";
cin >> penalty;
if (homeHasBall == true) {
if (tolower(team) == 'h') {
if (tolower(repeat) == 'n') {
down++;
}
if (down > 4) {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else {
yardsTo1stDown += penalty;
}
} else {
if (tolower(repeat) == 'n') {
down++;
}
yardsTo1stDown -= penalty;
if (yardsTo1stDown <= 0) {
yardsTo1stDown = 10;
down = 1;
} else if (down > 4) {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
}
}
} else {
if (tolower(team) == 'v') {
if (tolower(repeat) == 'n') {
down++;
}
if (down > 4) {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else {
yardsTo1stDown += penalty;
}
} else {
if (tolower(repeat) == 'n') {
down++;
}
yardsTo1stDown -= penalty;
if (yardsTo1stDown <= 0) {
yardsTo1stDown = 10;
down = 1;
} else if (down > 4) {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
}
}
}
} else if (choice == 'c') {
return 1;
} else {
cout << "Invalid choice. Please choose again. ";
}
}
cout << " Game Over"<< " Final Score Home [" << home << "] " << homeScore << " Visitors [" << visitor << "] " << visitorScore << endl << endl;
cout << "Is there another Game (Y/N)? ";
cin >> choice;
if (tolower(choice) == 'n')
anotherGame = false;
gameIsOver = true;
}
return 0;
}

Its being complied and run in DevC++

Explanation / Answer

please rate - thanks

I don't know football, so wasn't able to test, I also only added the penalty code only to the home-if it works add to visitor. get back to me and we can fix anything else

I don't know how to get to extra or end of game to test the changes

#include <iostream>
#include <string>
using namespace std;
int main() {
bool anotherGame = true, gameIsOver = false,skip;
bool homeHasBall;
string home, visitor, qrtrStr, hasBallStr;
char receiving, choice;
int quarter, homeScore, visitorScore, down, yardsTo1stDown;
cout << " 2010 Football Playoff Referee's Assistant ";
while(anotherGame == true) {
gameIsOver = false;                
cout << "What is the home team Mascot name? ";
cin >> home;
cout << "What is the visiting team Mascot name? ";
cin >> visitor;
cout << "Which Team has elected to receive the ball (H\V)? ";
cin >> receiving;
cout << endl;
if (tolower(receiving) == 'h')
       homeHasBall = true;
else
       homeHasBall = false;

cout << "EventCode Description EventCode Description ";
cout << "y Yardage made on play t Ball turned over ";
cout << "f Field Goal q Quarter is over ";
cout << "g Goal (touchdown) p Penalty ";
cout << "s Safety C Game Canceled ";

quarter = 1;
homeScore = 0;
visitorScore = 0;
yardsTo1stDown = 10;
down = 1;
while (gameIsOver == false) {
       if (quarter == 1)
             qrtrStr = "1st";
       else if (quarter == 2)
             qrtrStr = "2nd";
       else if (quarter == 3)
             qrtrStr = "3rd";
       else
              qrtrStr = "4th";
       if (homeHasBall == true)
               hasBallStr = "H [" + home + "]";
       else
               hasBallStr = "V [" + visitor + "]";
       cout << "Scoreboard: " << qrtrStr << " Quarter Ball Possession " << hasBallStr << endl;
       cout << "Home [" << home << "] " << homeScore << " Visitors [" << visitor << "] " << visitorScore << " Down " << down << " " << yardsTo1stDown << " Yards to first down" << endl;
       cout << "What event? ";
       cin >> choice;
       choice = tolower(choice);
       if (choice == 'y') {
               int yards;
               cout << "How many yards gained? ";
               cin >> yards;
               yardsTo1stDown -= yards;
               if (yardsTo1stDown <= 0) {
                   yardsTo1stDown = 10;
                   down = 1;
                   }
               else
                   {
                    down++;
                    }
if (down > 4) {
      yardsTo1stDown = 10;
      down = 1;
      homeHasBall = !homeHasBall;
      }
} else if (choice == 'f') {
if (homeHasBall)
homeScore += 3;
else
visitorScore += 3;
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 'g') {
int extra;
cout << "How many extra points? ";
cin >> extra;
while (extra > 2 || extra < 0) {
cout << "Invalid number of extra points-re-enter. ";
cout << "How many extra points? ";
cin >> extra;
}
if (homeHasBall)
homeScore += 6 + extra;
else
visitorScore += 6 + extra;
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 's') {
if (homeHasBall)
visitorScore += 2;
else
homeScore += 2;
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 't') {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else if (choice == 'q') {
quarter++;
if (quarter > 4)
gameIsOver = true;
else if (quarter == 3) {
cout << "End of 1st Half"<<" Home [" << home << "] " << homeScore << " Visitors [" << visitor << "] " << visitorScore << endl<<endl;
if (tolower(receiving) == 'h')
homeHasBall = false;
else
homeHasBall = true;
yardsTo1stDown = 10;
down = 1;
}
} else if (choice == 'p') {
char team, repeat;
int penalty;
cout << "Which team (H/V)? ";
cin >> team;
cout << "Repeat of down (Y/N)? ";
cin >> repeat;
cout << "Yards penalized? ";
cin >> penalty;
skip=false;                                 //
if (homeHasBall == true)
    {if (tolower(team) == 'h')
        {if (tolower(repeat) == 'n')
             {down++;
             }
         if (down > 4)
               {homeHasBall = !homeHasBall;
                yardsTo1stDown = 10;
                down = 1;
                }
          else if(down==4)                    //
               {yardsTo1stDown -= penalty;    //
                if (yardsTo1stDown <= 0) {    //
                     yardsTo1stDown = 10;          //
                     down = 1;                     //
                     }                            //
                skip=true;                  //
                }                            //
                        
          else
               {yardsTo1stDown += penalty;
               }
          }
      else
          {if (tolower(repeat) == 'n')
               {down++;
           }
if(!skip)                         //
{                                 //
    yardsTo1stDown -= penalty;
    if (yardsTo1stDown <= 0) {
         yardsTo1stDown = 10;
         down = 1;
        }
    else
        if (down > 4) {
             homeHasBall = !homeHasBall;
             yardsTo1stDown = 10;
             down = 1;
            }
   }
}                                     //
} else {
if (tolower(team) == 'v') {
if (tolower(repeat) == 'n') {
down++;
}
if (down > 4) {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
} else {
yardsTo1stDown += penalty;
}
} else {
if (tolower(repeat) == 'n') {
down++;
}
yardsTo1stDown -= penalty;
if (yardsTo1stDown <= 0) {
yardsTo1stDown = 10;
down = 1;
} else if (down > 4) {
homeHasBall = !homeHasBall;
yardsTo1stDown = 10;
down = 1;
}
}
}
} else if (choice == 'c') {
return 1;
} else {
cout << "Invalid choice. Please choose again. ";
}
}
cout << " Game Over"<< " Final Score Home [" << home << "] " << homeScore << " Visitors [" << visitor << "] " << visitorScore << endl << endl;
cout << "Is there another Game (Y/N)? ";
cin >> choice;
if (tolower(choice) == 'n')
       anotherGame = false;
//gameIsOver = true;
      
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote