Thread: Date and W/L Help

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    Question Date and W/L Help

    I don't know how to add W/L and the date to my output file. The output asks W/L, date, home team score, opp team score, and spread. I've gotten the code written for the most part I just don't know how to add whether the team W/L and the date. Here's my source code:

    Code:
    #include<stdio.h>
    main()
    {
          int e,gamesPlayed,won,lost;
          float wuTot,oppTot,spreadTot,spread,wuScore,oppScore;
          float wuAvg,oppAvg,spreadAvg,date;
          FILE *payInFile, *payOutFile;
          payInFile = fopen("dataS.txt","r");
          payOutFile = fopen("outS.txt","w");
          fprintf(payOutFile, "Bradley Lantz Project 2 Due 10/6/11");
          fprintf(payOutFile, "CM111 Barker\n\n");
          fprintf(payOutFile, "WU Football '10 Statistics\n");
          fprintf(payOutFile, "WU   OPP   SPREAD\n");
          wuTot=0;
          oppTot=0;
          spreadTot=0;
          gamesPlayed=0;
          won=0;
          lost=0;
          e=fscanf(payInFile, "%f %f", &wuScore, &oppScore);
          while (e==2)
          {
                wuTot=wuTot+wuScore;
                oppTot=oppTot+oppScore;
                if (wuScore > oppScore)
                   {
                    won=won+1;
                    }
                else
                    {
                     lost=lost+1;
                     }        
                spread=wuScore-oppScore;
                spreadTot=spreadTot+spread;
                gamesPlayed=gamesPlayed+1;
                fprintf(payOutFile, "%2.0f %5.0f %5.0f\n", wuScore, oppScore, spread);
                e=fscanf(payInFile, "%f %f", &wuScore, &oppScore);
                }
          spreadAvg=spreadTot/gamesPlayed;
          wuAvg=wuTot/gamesPlayed;
          oppAvg=oppTot/gamesPlayed;
          fprintf(payOutFile, "                              ");
          fprintf(payOutFile, "WU        OPP      SPREAD\n");
          fprintf(payOutFile, "  Totals for season to date:");
          fprintf(payOutFile, "%5.0f %8.0f %9.0f\n", wuTot, oppTot, spread);
          fprintf(payOutFile, "Averages for season to date:");
          fprintf(payOutFile, "%7.2f %9.2f %9.2f\n", wuAvg, oppAvg, spreadAvg);
          fprintf(payOutFile, "WU Football's Current Record is ");
          fprintf(payOutFile, "%d", won);
          fprintf(payOutFile, " - ");
          fprintf(payOutFile, "%d", lost);
          }
    If anybody can help me figure it out that would be appreciated. Thanks!!!

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    You need to define W/L and date for us. I assume W/L is win/loss record, so it might be something like "Wins: 6 Losses: 2". Perhaps you need to print how many draws/ties there were too. As for date, is it supposed to be the today's date? If so, there are lots of great functions in time.h.

    Some other notes on your code:

    1. Your indentation is a little messy, making it hard to read.
    2. It's int main(void) and return an int at the end (usually 0 for success). Read this.
    3. You need to check the return value of both fopen calls. If either returns NULL, print an error message (the perror() function is good for this) and abort.
    4. Good job on checking the return value of fscanf. You can clean up your loop a little though (see example below).
    5. You can simplify a = a + 1; by using a++; instead. You can simplify a = a + b; with a += b;.


    Code:
    while (fscanf(payInFile, "%f %f", &wuScore, &oppScore) == 2)
    {
        ...
        // no need for the 'e' variable, or to call fscanf again down here, it's all done when checking the loop condition
    }

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    The date is predefined (past dates of football games) W/L is defined as just off to the side either a W for a win or an L for a loss. The sample output should look something like:

    W/L Date WU OPP SPREAD
    W 9/04 33 13 20

    I've got the rest of the report figured out. I just have no idea how to input multiple predefined dates (one date per record) and how to determine if it's W or L.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    Also thanks for the other suggestions! I really appreciate the help.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by kamperkid View Post
    The date is predefined (past dates of football games) W/L is defined as just off to the side either a W for a win or an L for a loss. The sample output should look something like:

    W/L Date WU OPP SPREAD
    W 9/04 33 13 20

    I've got the rest of the report figured out. I just have no idea how to input multiple predefined dates (one date per record) and how to determine if it's W or L.
    Well, I don't know how the dates are stored in your input file, so I can't say how to read them in. Perhaps you could post a few lines from your input file? As for the W/L column, you already calculate whether the game was a win or a loss:
    Code:
            if (wuScore > oppScore)
            {
                won=won+1;
            }
            else
            {
                lost=lost+1;
            }
    Just print the A 'W' or an 'L' in there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is C out of date?
    By CSaw in forum C Programming
    Replies: 68
    Last Post: 07-21-2010, 09:40 AM
  2. Two date objects showing same date?
    By dxfoo in forum C++ Programming
    Replies: 7
    Last Post: 06-17-2010, 06:06 PM
  3. Getting the Following Date
    By BB18 in forum C Programming
    Replies: 2
    Last Post: 10-10-2004, 12:39 PM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  5. date
    By Foane in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 01:46 PM