This program is supposed to calculate how much a person would earn over a period of time if his salary was I penny the 1st day, two pennies the 2nd day, 4 pennies the 3rd day, 8 pennies the 4th day and so on.
The program should ask the user for the number of days. Then, it is to display a table showing how much the salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies.
I was told that I should use a while loop for input validation because it's not supposed to accept a number less than 1 for the number of days worked.
The formula is 2^n-1
Finally, I tried to use a for loop to do the calculation because it's supposed to display a list of totals for each day.
If you could copy and paste and correct this for me, I would greatly appreciate it thanks.
2007-11-09
04:04:05
·
6 answers
·
asked by
USAman
6
in
Computers & Internet
➔ Programming & Design
// bla bla...
#include
#include
using namespace std;
int main ()
{
int days1;
int days2;
double total = 0.0;
cout << "Enter the amount of days.n\ ";
cin >> days1;
while (day1 < 1)
{
cout << "ERROR: You can't enter a value less than 1. ";
cin >> days1;
}
for (int count = 1; count <= days1; count ++)
{
total += pow(2.0), days1 -1;
}
cout << "The total earned is $" << total << endl;
return 0;
}
2007-11-09
04:04:29 ·
update #1