Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: void functions for soccer match  (Read 2871 times)

0 Members and 1 Guest are viewing this topic.

Tweetilicous

    Topic Starter


    Starter

    void functions for soccer match
    « on: March 18, 2009, 11:34:05 AM »
    hi
    i have this program but cannot find problem.
    it suppose to enter the points of a soccer team & where they played.then it must calculate the total points of the games played at home by the team & the points of the opponents.As well as the points played away from home by team & opponents.but it only reads in the last entry.
    i think my void functions is wrong bt dnt knw wat to change it to!!!
    please help!!! please
    //assignment 2 Question 5
    #include <iostream>
    using namespace std;
    int nr_matches = 9;


    void inputAndValidated (int & pointsForp,int & pointsAgainstp, char & wherep)
    {
       
        for(int i=0; i< 4; i++)
        {
        do
        {   
            cout<<"Where was the match played? ";
            cin>> wherep;
            cout<<endl;
        }while((wherep != 'H' ) &&(wherep != 'A'));
       
        cout<<"Enter the number of points scored by the Lions : ";
        cin>> pointsForp;
        cout<<"Enter the number of points scored by the opponents: ";
        cin>> pointsAgainstp;
     
        }
    }
    void updateTotalsHome (int teamsPoint,int opponentsPoints, int & teamsTotal ,int & opponentsTotal)
    {
        teamsTotal= 0;
        opponentsTotal=0;
        teamsTotal += teamsPoint;
        opponentsTotal += opponentsPoints;
       

    }

    void updateTotalAway(int teamsPointA,int opponentsPointsA,int & teamsTotalA ,int & opponentsTotalA)
    {
        teamsTotalA=0;
        opponentsTotalA=0;
        teamsTotalA += teamsPointA;
        opponentsTotalA += opponentsPointsA;
       


    int main()
    {
        int pointsFor,pointsAgainst;
        int totalForHome,totalAgainstHome,totalForAway,totalAgainstAway;
        int nrHome,nrAway;
        char where;
        // initialise totals
        totalForHome=0;
        totalAgainstHome=0;
        totalForAway= 0;
        totalAgainstAway=0;
        nrHome=0;
        nrAway=0;
       
        inputAndValidated(pointsFor,pointsAgainst,where);
       
       
       if(where =='H')
       {
          nrHome++;
          updateTotalsHome(pointsFor,pointsAgainst, totalForHome,totalAgainstHome);
       }
       else
       {
          nrAway++;
          updateTotalAway(pointsFor,pointsAgainst,totalForAway,totalAgainstAway);
       }
       cout<<"The total at this point is: "<<endl<<endl;
       cout<<"Played at home: "<<endl;
       cout<<"Total points scored by the team  "<<totalForHome<<endl;
       cout<<"Total points scored by the opponents "<<totalAgainstHome<<endl;
       cout<<endl;
       cout<<"Played away from home: "<<endl;
       cout<<"Total points scored by the team  "<<totalForAway<<endl;
       cout<<"Total points scored by the opponents "<<totalAgainstAway<<endl;
       
        cout<<endl;
       
        return 0 ;
    }