### doubling output wrong

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include "stdafx.h" #include using namespace std; int main(double pay) { int days; float daily; double total; cout << "This will display the total salary at the end of the month.\n\n" << endl; cout.setf(ios_base::fixed , ios_base::floatfield); cout.precision(2); cout << "Enter how many days you worked in the month: "; cin >> days; cout << "Enter the daily pay in pennies meaning cents: \$"; cin >> daily; cout << "\n\n"; while (days < 1 || days > 31) { cout << "Please re-enter the data, days must be greater than 0 and less than or equal to 31.\n\n"; cout << "Enter how many days you worked in the month: "; cin >> days; cout << "Enter the daily pay in pennies meaning cents: "; cin >> daily; cout << "\n\n"; } for (int dys = 1 ; dys <= days ; dys++) { pay *= 2; cout << dys << " " << pay; cout << endl; } total =+ pay + pay; cout << "\n\n"; cout << "Your total salary is \$" << total << endl; cout << endl << "Press ENTER to exit..."; cin.clear(); cin.sync(); cin.get(); return 0; }``````

say i enter i worked 3 day and the pay each day was \$0.02

its suppose to double so example

day 1 0.02
day 2 0.04
day 3 0.08

the pay is suppose to double, but when i run my program the pay is always showing 0.00 for everything.

can anyone see why.
This is the first time I have seen anyone do this:

`int main(double pay)`

The normal convention is to use the following for program arguments:

 ``1234`` ``````int main(int argc, char *argv[]) { return 0; }``````

If this look's too tricky, just get input for the pay variable with cin.
Last edited on
ok, heres my updated code.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include "stdafx.h" #include using namespace std; int main() { int days; float pay; double total; cout << "This will display the total salary at the end of the month.\n\n" << endl; cout.setf(ios_base::fixed , ios_base::floatfield); cout.precision(2); cout << "Enter how many days you worked in the month: "; cin >> days; cout << "Enter the daily pay in pennies meaning cents: \$"; cin >> pay; cout << "\n\n"; while (days < 1 || days > 31) { cout << "Please re-enter the data, days must be greater than 0 and less than or equal to 31.\n\n"; cout << "Enter how many days you worked in the month: "; cin >> days; cout << "Enter the daily pay in pennies meaning cents: "; cin >> pay; cout << "\n\n"; } for (int dys = 1 ; dys <= days ; dys++) { pay *= 2; cout << dys << " " << pay; cout << endl; } total =+ pay + pay; cout << "\n\n"; cout << "Your total salary is \$" << total << endl; cout << endl << "Press ENTER to exit..."; cin.clear(); cin.sync(); cin.get(); return 0; }``````

now when i enter 3 days worked and 0.02 as the pay

the table comes up and displays

1 0.04
2 0.08
3 0.16

and my total displays 32.

The correct output should be

1 0.02
2 0.04
3 0.08

total should display 0.14

got any ideas on how to fix this.
Last edited on
Try this code ..
 ``123456789`` ``````double total = 0 ; for (int dys = 1 ; dys <= days ; dys++) { cout << dys << " " << pay << endl; total = total + pay ; pay *= 2 ; } cout << "Total " << total << endl;``````

Try using do while loop when asking for pay and days so that you don't have to write the same lines again.
ok and thank you guys it works now.
Topic archived. No new replies allowed.