11 Replies - 485 Views - Last Post: 07 December 2012 - 06:22 PM Rate Topic: -----

#1 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

football referee helper

Posted 05 December 2012 - 03:42 PM

Hello again,

I have to write a program that helps the referee keep track of whats going on in a foot ball game.

I have a lot of it done and only hung up on a couple things right now. The output of lines 20-31 are the general format the display need to be in.

My first problem is my switch is not working and I can not see where its getting jammed up. I lets me select my option but instead of displaying what it should it crashes or something.

Second I have to program the ball possession and turn over parts. I know I have to use a boolean expression, but I am drawing a blank on how to set it up. I want to set it up so the home team info is one function and visitors another. Is that even possible?

Anyhow, here is my code so far.

//Football Referee Helper

#include <iostream>

using namespace std;

int main() 
{
    //needs pos config
    int yd=0, qrt=1, hscr=0, vscr=0, dwn=1, scr, p;
    char pos, code, v, h, rd;
    string hm, vm, mas;

    cout<<"What is the home teams mascot? ";
    getline(cin,hm);
    cout<<"What is the visiting teams mascot? ";
    getline(cin,vm);
    cout<<"What team will begian with possetion (h/v)? ";
    cin.get(pos);    // pos needs config
    cout<<"\n\nThe Event Codes are as follows: "<<endl;
    cout<<"\n Code\t    Description \t Code\t    Description"<<endl;
    cout<<"  y\tYardage made on play \t  t\tBall turned over"<<endl;
    cout<<"  f\tField Goal \t \t  q\tQuarter is over"<<endl;
    cout<<"  g\tGoal (Touchdown) \t  p\tPenalty"<<endl;
    cout<<"  s\tSafty \t\t\t  c\tGAME CANCELED"<<endl;
    cout<<"\nCurent Status: "<<qrt<<" Quarter\t\Ball Possession ";
    cout<<pos<<"["<<mas<<"]"<<endl;
    cout<<"Home ["<<hm<<"] "<<hscr<<"\tVistors ["<<vm<<"] "<<vscr<<"\tDown ";
    cout<<dwn<<"\t\t"<<10-yd<<" yards to 1st down."<<endl;
    cout<<"\nWhich event? ";
    cin>>code;
    
    switch(toupper(code))
    {
      case 'Y': "yardage gained"; break;
                cout<<"How much yards were gained on the play? ";
                cin>>yd;
                yd+=yd;

                if (yd<10)
                { dwn++;
                  if (dwn==4)  //needs turn over status
                  cout<<"Ball turned over";
                }
      case 'F': "Field Goal"; break;
                scr+=3;
      case 'G': "Goal"; break;
                cout<<"How many points scored? "<<endl;
                cin>>scr;
                scr=+6;
      case 'S': "Safty"; break;
                scr+=2;   //need turn over status
      case 'T': "Ball turned over"; break;
           // needs turn over status
      case 'Q': "Quarter over"; break;
           qrt++;
      case 'P': "Penalty"; break;
                cout<<"Thich team (H/V)? ";
                cin>>pos;
                cout<<"Repeat of downs? (Y/N)";
                cin>>rd;
                cout<<"Yards Penalized? ";
                cin>>p;
                       yd-=p;
           
      case 'C': "Game Caneled"; break;
      default: cout<<"Invalid Selection "<<endl;
      }

  
    cin.get();
    cin.get();
    return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: football referee helper

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,239
  • Joined: 20-March 10

Re: football referee helper

Posted 05 December 2012 - 05:02 PM

Hi,

The way a switch statement normally works is by

switch(code)

{

   case  1:


           //  do  something
           cout << "something"  << endl;

        break;

}

see break is not at the beginning but at the end....


Best Wishes


Snoopy.
Was This Post Helpful? 0
  • +
  • -

#3 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 05 December 2012 - 05:20 PM

Thanks Snoopy. I didn't even notice that. You have a good eye.
I have been trying to set up how the ball possession is handled. I am not sure if I am on the right path though.
I have it set up as a function but have it commented out right now.

My code now looks like this.
//Football Referee Helper

#include <iostream>

using namespace std;

//void possession(char, char);

int main()
{
    //needs pos config
    int yd=0, qrt=1, hscr=0, vscr=0, dwn=1, scr, p;
    char pos, code, v, h, rd, n;
    string hm, vm, mas;

    cout<<"What is the home teams mascot? ";
    getline(cin,hm);
    cout<<"What is the visiting teams mascot? ";
    getline(cin,vm);
    cout<<"What team will begian with possetion (h/v)? ";
    cin.get(pos);    // pos needs config
    cout<<"\n\nThe Event Codes are as follows: "<<endl;
    cout<<"\n Code\t    Description \t Code\t    Description"<<endl;
    cout<<"  y\tYardage made on play \t  t\tBall turned over"<<endl;
    cout<<"  f\tField Goal \t \t  q\tQuarter is over"<<endl;
    cout<<"  g\tGoal (Touchdown) \t  p\tPenalty"<<endl;
    cout<<"  s\tSafty \t\t\t  c\tGAME CANCELED"<<endl;
    cout<<"\nCurent Status: "<<qrt<<" Quarter\t\Ball Possession ";
    cout<<pos<<"["<<mas<<"]"<<endl;
    cout<<"Home ["<<hm<<"] "<<hscr<<"\tVistors ["<<vm<<"] "<<vscr<<"\tDown ";
    cout<<dwn<<"\t\t"<<10-yd<<" yards to 1st down."<<endl;
    cout<<"\nWhich event? ";
    cin>>code;

    switch(toupper(code))
    {
      case 'Y': "yardage gained"; break;
                cout<<"How many yards were gained on the play? ";
                cin>>yd;
                yd+=yd;

                if (yd<10)
                { dwn++;
                  if (dwn==4)  //needs turn over status
                  cout<<"Ball turned over";
                }
                break;
      case 'F': "Field Goal";
                scr+=3;
                break;
      case 'G': "Goal";
                cout<<"How many points scored? "<<endl;
                cin>>scr;
                scr+=scr;
                break;
      case 'S': "Safty";
                scr+=2;
                break;  //need turn over status
      case 'T': "Ball turned over";
           // needs turn over status
                break;
      case 'Q': "Quarter over";
                qrt++;
                break;
      case 'P': "Penalty";
                cout<<"Which team (H/V)? ";
                cin>>pos;
                cout<<"Repeat of downs? (Y/N)";
                cin>>rd;
                    if (rd==n)
                        dwn++;
                cout<<"Yards Penalized? ";
                cin>>p;
                    yd-p;
                break;

      case 'C': "Game Canceled";
                cout<<"Game Canceled"<<endl;
                break;
      default: cout<<"Invalid Selection "<<endl;
      }


    cin.get();
    cin.get();
    return 0;
}
/*void possession(char, char)
{
    char pos, h;
    int vscr, hscr, scr;
    string mas, hm, vm;

    if (pos==h)
        {
        scr=hscr;
        mas=hm;
        }
    else
        {
        scr=vscr;
        mas=vm;
        }
}
*/


Was This Post Helpful? 0
  • +
  • -

#4 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 05 December 2012 - 05:26 PM

Sorry about putting this in the same post. I hit reply not preview. I still have the same problem with the switch.
Was This Post Helpful? 0
  • +
  • -

#5 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 05 December 2012 - 06:04 PM

Solved the switch problem thanks to Snoopy. I still had the issue because I forgot to delete a break from the from the first case. Anyone have any ideas about how i should handle the ball possession? As i stated earlier I want to set it up so that when either side is selected it handles the scoring and mascots as well.

E.G. This is based off who has possession of the ball.

if(posssession==H)
  { score=homeScore;
   mascot=homeMascot;}
else
   {score=visitorScore;
   mascot=visitorMascot;}


Would something like this be possible?
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,239
  • Joined: 20-March 10

Re: football referee helper

Posted 05 December 2012 - 08:28 PM

Hi,


You could do something like


int  possession(char poss, int hScore, int vScore, string hm, string vm, string *mas)
{


    int scr = 0;

    if (poss=='h')
    {
        scr=hScore;
        *mas=hm;
    }
    else
    {
        scr=vScore;
        *mas=vm;
    }

    return scr;

}






Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#7 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 06 December 2012 - 09:28 AM

Snoopy,

I set up the function like you suggested and I get a single compiling error. The error is: line 25 error: no match for 'operator*'in '*mas'.

When I remove the '*' I get a lengthy error line 25 error: can not convert 'std::string' to 'std::string*' error for argument 6 to the same line.

I don't understand what I did wrong.

//Football Referee Helper

#include <iostream>
#include <cctype>

using namespace std;

int ballPos(char poss, int hscr, int vscr, string hm, string vm, string *mas);

int main()
{
    //needs pos config
    int yd=0, qrt=4, hscr=0, vscr=0, dwn=1, scr=0, p;
    char pos, code, V, H, rd, n, again;
    string hm, vm, mas;

  do
  {
    cout<<"What is the home teams mascot? ";
    getline(cin,hm);
    cout<<"What is the visiting teams mascot? ";
    getline(cin,vm);
    cout<<"What team will begian with possetion (H/V)? ";
    cin.get(pos);
        ballPos(pos,hscr,vscr,hm,vm,*mas);
    // pos needs config
    cout<<"\n\nThe Event Codes are as follows: "<<endl;
    cout<<"\n Code\t    Description \t Code\t    Description"<<endl;
    cout<<"  y\tYardage made on play \t  t\tBall turned over"<<endl;
    cout<<"  f\tField Goal \t \t  q\tQuarter is over"<<endl;
    cout<<"  g\tGoal (Touchdown) \t  p\tPenalty"<<endl;
    cout<<"  s\tSafty \t\t\t  c\tGame Canceled"<<endl;
    do
    {
    cout<<"\nCurent Status: "<<qrt<<" Quarter\tBall Possession ";
    cout<<pos<<"["<<mas<<"]"<<endl;
    cout<<"Home ["<<hm<<"] "<<hscr<<"\tVistors ["<<vm<<"] "<<vscr<<"\tDown ";
    cout<<dwn<<"\t\t"<<yd<<" yards to 1st down."<<endl;
    cout<<"\nWhich event? ";
    cin>>code;

    switch(toupper(code))
    {
      case 'Y': "yardage gained";
                cout<<"How many yards were gained on the play? ";
                cin>>yd;
                    yd=10-yd;
                if (yd>10)
                    yd=0;
                if (yd<10)
                {

                    dwn++;
                    if (dwn>4)  //needs turn over status
                        {
                            cout<<"Ball turned over";
                            dwn=0;
                        }
                }
                break;

      case 'F': "Field Goal";
                scr+=3;
                break;

      case 'G': "Goal";
                cout<<"How many points scored? "<<endl;
                cin>>scr;

                break;

      case 'S': "Safty";
                scr+=2;
                break;  //need turn over status

      case 'T': "Ball turned over";
           // needs turn over status
                break;

      case 'Q': "Quarter over";
                qrt++;
                if (qrt>4)
                {
                    cout<<"\nGame Over\tFinal Score\tHome ["<<hm<<"]\t"<<hscr;
                    cout<<"\tVisitors ["<<vm<<"]\t"<<vscr<<endl;
                    cout<<"############ "<<mas<<" Win!! ###############";
                }
                break;

      case 'P': "Penalty";
                cout<<"Which team (H/V)? ";
                cin>>pos;
                cout<<"Repeat of downs? (Y/N)";
                cin>>rd;
                    if (rd==n)
                        dwn++;
                cout<<"Yards Penalized? ";
                cin>>p;
                    yd-=p;
                break;

      case 'C': "Game Canceled";
                cout<<"\nGAME CANCELED!!"<<endl;
                break;

      default: cout<<"Invalid Selection "<<endl;
    }
  }
    while(code!='C');

    cout<<"Is there another Game";
    cin.get(again);
    }
    while (again!=n);

    cin.get();
    cin.get();
    return 0;
}

int ballPos(char poss, int hscr, int vscr, string hm, string vm, string *mas)
{


    int scr = 0;

    if (poss=='h')
    {
        scr=hscr;
        *mas=hm;
    }
    else
    {
        scr=vscr;
        *mas=vm;
    }

    return scr;

}


Was This Post Helpful? 0
  • +
  • -

#8 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: football referee helper

Posted 06 December 2012 - 09:46 AM

You need to pass the address of mas to the function: &mas in the function call...
Here,
025	        ballPos(pos,hscr,vscr,hm,vm,*mas);

Was This Post Helpful? 0
  • +
  • -

#9 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 06 December 2012 - 10:27 AM

Ahhhh. I knew it was something simple.

Thanks AK
Was This Post Helpful? 0
  • +
  • -

#10 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 06 December 2012 - 04:24 PM

now I am having trouble with the score updating in the status, I thought the possession function would handle that. But for some reason it's not. I tried to passed the home team's score into the function and use it as a pointer like the mascot. But, I get 2130567168 number when the score should be zero. A couple more issues that have arose are. do while loops are printing double do's if they have double while expression to test.

E.g.
do
{
cout<<"Are you done? ";
cin>>x;
}
while (x!=Y || x!=y);.


user input
Are you done? n
Are you done? Are you done?

I am at a lose at what is plaugging this program
Was This Post Helpful? 0
  • +
  • -

#11 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 06 December 2012 - 06:48 PM

Ok, after a break from my codding. I solved most my problems. Now all that remain are:

1)Getting my variable of who has possession to always display upper case.
cin>>(toupper(pos));
Does not work for me.

2)I started the turnover status. The function is commented out at the moment.

3)A loop error or two that are commented out.

4)I have to get the score to increment correctly for field goals and safeties. My code for a safety is not adding to the score of the team in possession. The same for the field goal.

case 'S': "Safty";
           if (pos=='H')
               hscr+2;
           else
               vscr+2;
               break;  //need turn over status



Here is my code in entirity:

//Football Referee Helper
//needs turnover status and configuring for scores

#include <iostream>
#include <cctype>


using namespace std;

void ballPos(char pos, string hm, string vm, string *mas);
//int score(int hscr, int vscr, char pos);

int main()
{

    int yd=10, qrt=1, hscr=0, vscr=0, dwn=1, scr, p, ydg;
    char pos, code, V, H, rd, N, again, tp;
    string hm, vm, mas;

  do
  {

    cout<<"What is the home teams mascot? ";
    getline(cin,hm);
    cout<<"What is the visiting teams mascot? ";
    getline(cin,vm);
    //do
    //{
        cout<<"What team will begian with possetion (H/V)? ";
        cin>>pos;
   // }
     //while(pos!='H' || pos!='V');
        ballPos(pos,hm,vm,&mas);
    // pos needs config
    cout<<"\n\nThe Event Codes are as follows: "<<endl;
    cout<<"\n Code\t    Description \t Code\t    Description"<<endl;
    cout<<"  y\tYardage made on play \t  t\tBall turned over"<<endl;
    cout<<"  f\tField Goal \t \t  q\tQuarter is over"<<endl;
    cout<<"  g\tGoal (TD, EP, or 2pt con) p\tPenalty";
    cout<<"\n  s\tSafty \t\t\t  c\tGame Canceled"<<endl<<endl;
    do
    {
    cout<<"\nCurent Status: "<<qrt<<" Quarter\tBall Possession ";
    cout<<pos<<"["<<mas<<"]"<<endl;
    cout<<"Home ["<<hm<<"] "<<hscr<<"\tVistors ["<<vm<<"] "<<vscr<<"\t  Down ";
    cout<<dwn<<"\t  "<<yd<<" yards to 1st down."<<endl;
    cout<<"\nWhich event? ";
    cin>>code;

    switch(toupper(code))
    {
      case 'Y': "yardage gained";
                cout<<"How many yards were gained on the play? ";
                cin>>ydg;
                    yd-=ydg;
                if (yd<0)
                {
                    yd=10;
                    dwn=1;
                }

                if (yd<10)
                {
                    dwn++;
                    if (dwn>4)  //needs turn over status
                        {
                            cout<<"Ball turned over";
                            dwn=1;
                            yd=10;
                        }
                }
                break;

      case 'F': "Field Goal";
                if (pos=='H')
                    hscr+3;
                else
                    vscr+3;
                //needs turn over status
                break;

      case 'G': "Goal";
                cout<<"How many points scored? "<<endl;
                cin>>scr;
                    if (pos=='H')
                        hscr+=scr;
                    else
                        vscr+=scr;     //needs turn over status
                break;

      case 'S': "Safty";
                if (pos=='H')
                    hscr+2;
                else
                    vscr+2;
                break;  //need turn over status

      case 'T': "Ball turned over";

                // needs turn over status
                break;

      case 'Q': "Quarter over";
                qrt++;
                if (qrt>4)
                {
                    cout<<"\nGame Over\tFinal Score\tHome ["<<hm<<"]\t"<<hscr;
                    cout<<"\tVisitors ["<<vm<<"]\t"<<vscr<<endl;
                    cout<<"############ "<<mas<<" Win!! ###############";
                }
                break;

      case 'P': "Penalty";
                cout<<"Which team (H/V)? ";
                cin>>tp;
                cout<<"Repeat of downs? (Y/N)";
                cin>>rd;
                    if (toupper(rd==N)&& dwn<4)
                    {
                        dwn++;
                        if (dwn>4)  //needs turn over status
                            {
                                cout<<"Ball turned over";
                                dwn=0;
                            }
                    }

                cout<<"Yards Penalized? ";
                cin>>p;
                    if (tp==pos)
                        {
                            yd+=p;
                                if (dwn<4)
                                    dwn++;
                        }
                    else
                        {
                            yd-=p;
                                if (dwn<4)
                                    dwn++;
                        }                    //possibaly needs tunover status
                break;

      case 'C': "Game Canceled";
                cout<<"\nGAME CANCELED!!"<<endl;
                break;

      default: cout<<"Invalid Selection "<<endl;
    }
  }
    while(code!='C');
    cout<<" Is there another Game ";
    cin>>again;
    }
    while (toupper(again!='N'));

    cin.get();
    cin.get();
    return 0;
}

void ballPos(char pos, string hm, string vm, string *mas)
{
    if (pos=='H')
        *mas=hm;
    else
        *mas=vm;
    return;
}
/*bool turnOver(char pos)
{

        if (pos=='H')

        else

        return scr;
}*/


Was This Post Helpful? 0
  • +
  • -

#12 Nightspear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

Re: football referee helper

Posted 07 December 2012 - 06:22 PM

I have solved my field goal and safety problems. It was so simple that I could kick myself.

The next thing to tackle is breaking out of my switch loop. Can a do/while have more than one expression to test?

Then its on to the turn over status.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1