Originally Posted by
Salem
2 pennies for day 2
4 pennies for day 3
8 pennies for day 4
So are you supposed to be printing powers of two?
thats what i was thinking at first but it doesnt work...
NEVERMIND! before i posted this i wanted to try it out a couple times and i got it!!! i made the counter start at -1 so it would go to 0 and 1
so power to zero makes 1 penny and then power of 2 and so on.. heres the code!
Code:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int totalDays = 0, days = 1;
double pennies,pay, x=-1;
do{
cout << "How many days have you worked? ";
cin >> totalDays;
if(totalDays < 1)
cout << endl << "Pick up some hours please...re-enter." << endl
<< endl;
}while(totalDays < 1);
cout << setw(5) << left << endl << "Day #" << setw(17) << right << "Pay" << endl
<< "------------------------" << endl;
while(days <= totalDays)
{
x++;
pennies = pow(2, x);
cout << setw(5) << left << "Day " << days++ << setw(17) << right << pennies;
cout << endl;
}