Need help outputing months and days.

This is a discussion on Need help outputing months and days. within the C++ Programming forums, part of the General Programming Boards category; This program works fine but I am having trouble outputting the months and day and I can't seem to find ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Need help outputing months and days.

    This program works fine but I am having trouble outputting the months and day and I can't seem to find a way to display them on output as I continually getting 1,2,3,4 and so on under "week of" column . I need to have output that shows something like this below. Please help me fix this issue. Will appreciate it a lot.
    Week of Gallons Miles MPG February 4 9.8 196 42 February 11 9.5 182 42 February 18 5.6 101 42 February 25 7.5 133 42
    My Code:
    Code:
    #include <iostream>
    #include <cstring>
    using namespace std;
    #define Max_weeks 100
    int getNumberofweeks();
    int getGallonsamount(int,float*);
    int getMilesamount(int,float*);
    void CalcAverage(float[],int,float[]);
    float Gallons[Max_weeks];
    float Miles[Max_weeks];
    float MPG[Max_weeks];
    void display(int);
    void main()
    {
      int Numweeks;
      Numweeks = getNumberofweeks();
      getGallonsamount(Numweeks, Gallons);
      getMilesamount(Numweeks, Miles);
      CalcAverage(Gallons,Numweeks,Miles);
      display(Numweeks);
      cin.ignore(2);
    }
    int getNumberofweeks()     // functions that gets total number weeks
    {
        int weekInput;
       cout << "Enter the number of weeks: ";
       cin>>weekInput;
       cout<<endl;
       return weekInput;
    }
    int getGallonsamount (int count , float *MPG)    // function that gets amount of gallons
     {
        cout<<endl;
    
        for (int Gallons = 0; Gallons <count; ++Gallons)
        {
          cout << "enter amount of gallons for "<< Gallons+1 <<": ";
          cin >> *MPG;
          MPG++;
        }
        cout<<endl;
        return 0;
     }
    int getMilesamount (int count , float *MPG)   // function that get average miles
     {
        cout<<endl;
        for (int Miles = 0; Miles <count; ++Miles)
        {
          cout << "enter amount of miles for "<< Miles+1 <<": ";
          cin >> *MPG;
          MPG++;
        }
        cout<<endl;
        return 0;
     }
    void CalcAverage(float Gallons[],int count, float Miles[])  // function that calculates MPG
      {
         
        for (int week = 0; week < count; week++)
           {
               MPG[week] = (Miles[week]) / (Gallons[week]);
          }
      }
    void display(int count) // function that display the mark details along with total average
    {
         
          float TotalGallons=0.0;
          float TotalMiles=0.0,TotalMPG=0.0;  // variables for finding total
          float AvgMPG;                      // variables for finding average
          cout<<"\n\nWeek of"<<"\t\t"<<"Gallons"<<"\t"<<"Miles"<<"\t\t"<<"MPG"<<endl;
          string week[4] = {"February 4", "February 11","February 18","February 25"};
          for(int week=0; week<count ; week++) 
            
        {
            cout<<week+1<<"\t\t"<<Gallons[week]<<"\t"<<Miles[week]<<"\t\t"<<MPG[week]<<endl;
            TotalGallons = TotalGallons + Gallons[week];
            TotalMiles = TotalMiles + Miles[week];
            TotalMPG = TotalMPG + MPG[week];
          }
          {
          AvgMPG = TotalMPG / count;
          cout<<"\n Total Gallons :"<<TotalGallons;
          cout<<"\n Total Miles   :"<<TotalMiles;
          cout<<"\n Average MPG   :"<<AvgMPG;
        }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Perhaps something to do with having two variables with the same name?
    Code:
          string week[4] = {"February 4", "February 11","February 18","February 25"};
          for(int week=0; week<count ; week++)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculate Days Between 2 Months
    By Khadafi in forum C Programming
    Replies: 21
    Last Post: 02-12-2011, 01:46 PM
  2. Need help on outputing.....
    By tx1988 in forum C++ Programming
    Replies: 7
    Last Post: 04-17-2009, 12:03 PM
  3. summing number of days between 2 months
    By duff_johnny in forum C Programming
    Replies: 5
    Last Post: 11-03-2005, 01:36 PM
  4. After two months of c++...
    By the dead tree in forum Windows Programming
    Replies: 5
    Last Post: 04-28-2004, 06:28 PM
  5. See you in 15 months!
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 01-20-2003, 06:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21