Hi,

I am using this code:
int total = 0;
for (i = 0; i < 3; i++)
{
total+=hours_run;
cout <<"\n"<<total;
}

The aim of this code is too add up the hours run by the 3 people who enter the values.
The code above produces some weird results. instead of giving me one figure, it gives me three figure where it has added the three values together. for example

if the three values were 9, 4, & 3

It would come up like this
9 (+4)
13(+3)
16

16 is the right answer but is there any way i can just display 16 without the numbers above??
Please help???

sure, move the cout to outside the for loop.

int total = 0;
for (i = 0; i < 3; i++)
{
     total+=hours_run[i];
}
cout <<"\n"<<total;

Thanks man ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.