beginner loop problems...i think

so, I got this assignment:

Write a program that calculates the amount a person would earn over a period of time if his or her salary were one penny the first day, two pennies the second day, and so on doubling each day.



Your program should:

1. Request the number of days.

2. Display a table showing what the salary is for each day

3. Display the total pay



And for the life of me, I can't figure it out and it's starting to annoy me. Any thoughts? The end program should output this:

Day Pay

=======================

1 0.010000

...

5 0.1600

Your total pay is 0.3100

Thanks for any and all help. >.>
What is "it" that you can't figure out? What do you have so far?
I'm not exactly sure what function I need to be using or what values I need to be using to make it work. Either my loop would go crazy and never stop sending back results or it would just give me a single result of zero. So, I'm pretty confused right now. :/
Oh, btw, the example of what the output should look like is wrong, it should be:

Day Pay

================

1 $0.01

2 $0.02

3 $0.04

4 $0.08

5 $0.16

Your total pay is $0.31


Something you can use as inspiration:

1
2
3
4
5
6
7
8
int currentSalary=1,totalSalary=0;
for (int i=1;i<=days;i++)
{
  cout << "Day " << i << ": " << currentSalary << " cents" << endl;
  totalSalary+=currentSalary;
  currentSalary*=2;
}
cout << "Total salary: " << totalSalary << " cents" << endl;
Last edited on
Topic archived. No new replies allowed.