#include <iostream>
usingnamespace std;
int main()
{
int numDays = 1;
double money = 0.01;
cout<<"Enter number of days worked."<<endl;
cout<<endl;
cin>>numDays;
while (numDays <1)
{
cout<<"Invalid entry. Please enter a valid number (greater than 1)."<<endl;
cout<<endl;
cin>>numDays;
}
//start here
// end here
for (int i =1; i <= numDays; i++)
{
cout<<"You earned $"<<money<<"."<<endl;
cout<<endl;
money *=2;
}
return 0;
}
The problem is that I need only one line of output, and the YouTube video I was watching designed a table. I need the line to print the total dollar amount to two decimal places, not keep printing the amount for each day. How can I fix this?
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <iomanip>
using std::setw;
using std::setiosflags;
using std::setprecision;
#include <cmath>
int main()
{
int numDays = 1;
double money = 0.01;
cout<<"Enter number of days worked."<<endl;
cout<<endl;
cin>>numDays;
while (numDays <1)
{
cout<<"Invalid entry. Please enter a valid number (greater than 1)."<<endl;
cout<<endl;
cin>>numDays;
}
//start here
// end here
// set floating point number format
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
for (int i =1; i <= numDays; i++)
{
//cout << "You earned $" << money << endl;
//cout<<endl;
money = money + money*2;
}
cout << endl << "Total = " << money << endl;
return 0;
}