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.
#include <iostream>
#include <iomanip>
usingnamespace 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!
#include <iostream>
#include <iomanip>
usingnamespace 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;
}