PLEASE HELP

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include <iostream>
#include <iomanip>

using namespace 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;
}

This is a great time to use a recursive function. Put this in a for loop that will execute 30 times.

1
2
3
4
5
int double(int&penny)
{
   penny = penny * 2;
   return double(penny);
}
Last edited on
made a few adjustments to your original code, with some notes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <iomanip>
#include <limits>

using namespace 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;
}
Last edited on
This is a great time to use a recursive function. Put this in a for loop that will execute 30 times.

1
2
3
4
5
int double(int&penny)
{
   penny = penny * 2;
   return double(penny);
}


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..?
For the lawls.
For the lawls.

Why are you even on here?
For the lawls.


Troll Post
Aaand that's why you're banned.
Damn trolls.
Topic archived. No new replies allowed.