total on number and money counter switched

i'm having trouble understanding why the total gives the day instead of the number. when i enter 12 it should be $1.44 but it counts the days.i don't know why its not working.

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{

double numb = 1.00,total;
int days;



cout <<"please enter the ammount of days"<<endl;
cin >>days;



if (days <= 0)
{
cout <<"error your doing it wrong"<<endl;
cin >>days;
}

if (days > 0)
{
cout <<"pennie a day"<<endl;
cout <<"_________________"<<endl;

while (numb <= days)

{
cout << numb <<"\t\t"<<(numb * numb)<< endl;
numb++;

}




total = numb - 1 ;

cout<<"the total is " << total <<endl;//the total and days a switched



}



system("PAUSE");
return EXIT_SUCCESS;

}
Last edited on
Try this...move the total = numb -1 to right above the numb++;. And change it to the following code below. Also, next time use the code tag, easier for us to read. hehe.

total += numb * numb;

should looks like this afterward.

1
2
3
4
5
6
while (numb <= days)
{ 
cout << numb <<"\t\t"<<(numb * numb)<< endl;
total += numb * numb; 
numb++;
} 
Topic archived. No new replies allowed.