Program not counting up to days

The program is supposed to start with a penny and double daily. The assignment wants the day displayed to that day's amount. I am completely blanking as to why it keeps showing the user's input amount as the day every time. Any help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	int Days = 1;
	double Salary = 0.01;

	cout << "This program will have the user enter a number of days and will output their salary." << endl;
	cout << "Enter number of days worked:" << endl;
	cin >> Days;

	for (int i = 1; i <= Days; i++)
	{
		cout << setw(5) << "Day" << "\t\t\t" << "Pay" << endl;
		cout << "--------------------------------" << endl;
		cout << setw(4) << Days << "\t\t\t" << Salary << endl;
		cout << endl;
		Salary *= 2;

	}

	system("pause");
	return 0;

}
You should print "i" (the iterating variable for the for loop), not Days. Days is the variable that is holding the input so it would obviously print the input itself ;P!

Gotta be careful with variables. ;)
Hello ZestyCthulhu,

Your problem is in line 19. You are printing out "Days" which only has one number and never changes. I think what you want here is "i" not "Days".

I made some adjustments to your program. See what you think of this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	int Days = 1;
	double Salary = 0.01;

	cout << "This program will have the user enter a number of days and will output their salary." << endl;
	cout << "Enter number of days worked: ";
	cin >> Days;

	std::cout << std::fixed << std::showpoint << std::setprecision(2);  // <--- Added.

	cout << setw(5) << "Day" << "\t\t\t" << "Pay" << endl;  // <--- Moved these lines here.
	cout << "--------------------------------" << endl;

	for (int i = 1; i <= Days; i++)
	{
		cout << setw(4) << i << "\t\t\t" << std::setw(10) << Salary << endl;  // <--- Changed "Days" to "i".

		//cout << endl;
		Salary *= 2.0;  // <--- Changed to 2.0.


	}

	system("pause");
	return 0;

}


Hope that helps,

Andy
I finally got it working. Thank you so much everyone, this has had me stumped for hours.
Hello ZestyCthulhu,

You are welcome. It is always the little things that get you.

Andy
Topic archived. No new replies allowed.