program help

Sep 20, 2015 at 8:47pm
hi guys can you please help i am struggling to write this program... where ever i have put //help


#include <iostream>
using namespace std;

int main()
{
float mileage, highestMileage, totalMileage;
int i = 1, day = 1;

cout << "Enter mileage for November " << i << ": ";
cin >> mileage;
totalMileage = mileage;
highestMileage = mileage;

for (int i = 1 ; i <= day; ++i) //help
{
cout << "Enter mileage for November " << i << ": ";
cin >> mileage;
if ( > highestMileage) //help
{
day = ; //help
highestMileage = mileage;
}
totalMileage = ;//help
}

cout << "Total Mileage for November was :" << totalMileage << endl;
cout << "Highest Mileage was: " << highestMileage << " on " << day << " of November " << endl;

return 0;

Last edited on Sep 21, 2015 at 9:03am
Sep 20, 2015 at 10:38pm
Please edit and move to the Beginners section.

Also use [Code] [ /Code] tags so we can read it easily and explain exactly what you are having trouble understanding.
Sep 20, 2015 at 11:03pm
It looks like day should be the day of the highest mileage and you want to enter the mileage for each day in November. You enter the mileage for November 1 first, so this:
for (int i = 1 ; i <= day; ++i) //help should be
for (int i = 2 ; i <= 30; ++i) if ( > highestMileage) //help
You want to know if the current mileage is higher than the highest mileage so far, so it should be if ( mileage> highestMileage) day = ; //help You want to set day to the current day, which is i:
day = i; totalMileage = ;//help You want to sum up the mileage for each day, so that's:
totalMileage += mileage; (+= adds the right side to the variable on the left side)
Sep 21, 2015 at 9:00am
Thanks so much Dhayden... I understand it now.. i was having a hard time understanding the for loop with different integers..... Thanks again man!

My apologies James, first time here, although i will remember to post in the beginners section next time. thanks.
Topic archived. No new replies allowed.