I have a project due at midnight tonight that I cannot figure out. I need to write a program that will calculate a user's salary if their pay starts at a penny and doubles every day from then on for up to a month. I cannot figure out what formula to write to get my pay amounts to calculate and I do not know how to total them all up either. Please please help! This is the code I have so far.
#include <iostream>
#include <iomanip>
usingnamespace std;
#define MAX_DAYS 30
#define MIN_DAYS 1
#define START_PAY .01
int main()
{
int days, count;
double payAmount, total;
cout<<"How many days will you be working (1-30)? ";
cin>>days;
cout<<endl;
while (days < MIN_DAYS || days > MAX_DAYS)
{
cout<<"Error: the number of days must be between 1 and 30. Try again: ";
cin>>days;
cout<<endl;
}
cout<< "Days Pay Amount"<<endl;
cout<< "-----------------------------"<<endl;
for (count=1; count>=MIN_DAYS&&count<=MAX_DAYS; count++)
{
cout<<setw(2)<<count<<setw(22)<<payAmount<<endl;
}
return 0;
}
#include <iostream>
#include <iomanip>
#include <limits>
usingnamespace std;
#define MAX_DAYS 30
#define MIN_DAYS 1
#define START_PAY .01
int main()
{
int days;
double payAmount = 0.0, total = 0.0;
cout<<"How many days will you be working (1-30)? ";
cin>>days;
cout<<endl;
while (days < MIN_DAYS || days > MAX_DAYS)
{
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); // flush cin buffer in case a non-numeric was entered
cin.clear(); // clear cin error flags etc
cout<<"Error: the number of days must be between 1 and 30. Try again: ";
cin>>days;
cout<<endl;
}
cout<< "Days Pay Amount"<<endl;
cout<< "-----------------------------"<<endl;
payAmount = START_PAY; // first day standard pay
for(int count=0; count < days; count++)
{
if(count) payAmount *= 2; // first day, regular rate, then double every day thereafter
total += payAmount; // add payAmount to total
cout<<setw(2)<<count+1<<setw(22)<< "$" << std::fixed << std::setprecision(2)<<payAmount<<endl; // 2 decimal places
}
cout<< endl << "Total Pay: $" << std::fixed << std::setprecision(2) << total << endl;
return 0;
}
Why would you post a recursive function that calls itself infinitely into stack overflow that is also called double which is a data type so it wouldn't even compile..?