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; } }



LinkBack URL
About LinkBacks



