Results 1 to 6 of 6

Thread: please help.. but this is VC++

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Location
    MICHIGAN, USA
    Posts
    24

    Question please help.. but this is VC++

    The local baseball team is computerizing its records. You are to write a program that computes batting averages. There are 20 players on the team, identified by the numbers I through 20. Their batting records are coded in a file as follows.

    Each line contains four numbers; the player's identification number and the number of hits, walks, and outs he or she made in a particular game. Here is a sample;

    3 2 1 1

    The example above indicates that during a game, player number 3 was at bat four times and made 2 hits, I walk, and lout. For each player there are several lines in the file. Each player's batting average is computed by adding the player's total number of hits and dividing by the total number of times at bat. A walk
    does not count as either a hit or a time at bat when the batting average is being calculated. Your program prints a table showing each player's identification number, batting average, and number of walks. (Be careful; The players' identification numbers are I through 20, but C++ array indexes start at 0.)

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    First, this is C++, NOT Visual C++ (VC++)
    Second, C++ questions go in the C++ forum - that's why it's there.

    OK, try this:

    Code:
    #include <fstream.h>
    #include <iomanip.h>
    
    struct player
    {
        int hit;
        int battime;
    }
    
    player Team[20];
    
    int main()
    {
        ifstream input;
        int number, hit, walk, out;
    
        for(int i = 0; i < 20; i++)
        {
            Team[i].hit = 0;
            Team[i].battime = 0;
        }
    
        input.open("batting.dat");
    
        while (!input.eof())
        {
            input >> number >> hit >> walk >> out;
            Team[number - 1].hit += hit;
            Team[number - 1].battime += (hit + out);
    
            // Note: these are for compatibility reasons
            number = 1;
            hit = 0;
            walk = 0;
            out = 0;
        }
    
        cout << "ID#      Bat Avg  Walks";
        cout << "---------------------------";
        for(i = 0; i < 20; i++)
            cout << setw(9) << i + 1 << setw(9) << Team[i].hit << setw(9) << Team[i].battime;
    
        return 0;
    }


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3
    Hyperactive Member MikeBAM's Avatar
    Join Date
    Sep 2000
    Location
    Metro Detroit
    Posts
    284
    Yeah man use the 'C and C++' form. hehe.

    here: http://209.120.143.185/forumdisplay.php?s=&forumid=9
    ~* )v( ! /< E *~

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    In response to your PM:

    Code:
    #include <fstream.h>
    #include <iomanip.h>
    
    struct player
    {
        int hit;
        int battime;
    }
    
    player Team[20];
    
    int main()
    {
        ifstream input;
        int number, hit, walk, out;
    
        for(int i = 0; i < 20; i++)
        {
            Team[i].hit = 0;
            Team[i].battime = 0;
        }
    
        input.open("batting.dat");
    
        while (!input.eof())
        {
            input >> number >> hit >> walk >> out;
            Team[number - 1].hit += hit;
            Team[number - 1].battime += (hit + out);
    
            // Note: these are for compatibility reasons
            number = 1;
            hit = 0;
            walk = 0;
            out = 0;
        }
    
        input.close();  //add this
    
        cout << "ID#      Bat Avg  Walks";
        cout << "---------------------------";
        for(i = 0; i < 20; i++)
            cout << setw(9) << i + 1 << setw(9) << Team[i].hit << setw(9) << Team[i].battime;
    
        return 0;
    }
    If it didn't work, check if you added batting.dat in the same folder as the program with the data in THAT format.

    Also, don't PM people to respond to their posts. Use Reply. PM is used for certain messages and notifications, not responses.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    You shouldn't do peoples work for them!!
    Don't Rate my posts.

  6. #6
    Zaei
    Guest
    Agree. He didnt even ask...

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width