Calculating Monthly Salary with Doubling Formula

In summary, this conversation discusses the creation of a program that displays a person's salary for one month, starting with 1 dollar on the first day and doubling each day thereafter. The solution involves using a loop to calculate the salary and a running total to keep track of the overall salary for the month. The conversation also mentions the need to be prepared for a large number result.
  • #1
remaan
132
0

Homework Statement



In this problem, we are asked to write a program which displays the salary of a person for one month. Given that his salary for the first day is 1, second day 2 $ , third day 4$ , and contiue to double . And, then we have to display the total salary of the whole month.





The Attempt at a Solution


Her is the code I made

public class Ass3 {

public static void main (String args [])
{

int salary = 1;

System.out.println(salary);

for ( int d = 0 ; d < 29 ; d++)

{
salary *=2;
System.out.println(salary);

}


}

}


I tired with making total = 0 and then total = total + salary,
But it did Not work, even when putting inside the loop itself ?

What do you think ?
 
Physics news on Phys.org
  • #2
Go through the days of the month and each day work out the salary for that day and a running total up to the end of that day.

At the end of the month you have a month's salary in the total.
 
  • #3
what do you mean by : a running total up to the end of that day ?

What I thought about is initlizing a variable total = 0

and then add the salaries each day.

Right ??
 
  • #4
Yes, that is right.
Each day double the previous day's salary and add it to the total.

Before you start the loop, make the total = 0, the first day's salary = 1.
Then FDS= FDS * 2
Total = total + FDS

Be ready for a very big number.
 
  • #5
alright, thanks alot!

I am done with one right now,

Thanks a lot once again =)
 

1. How do you calculate monthly salary with doubling formula?

To calculate monthly salary with doubling formula, you need to know the starting salary and the number of months. Then, you can use the formula: monthly salary = starting salary * 2^(number of months - 1). For example, if the starting salary is $1000 and the number of months is 12, the monthly salary would be $1000 * 2^(12-1) = $1000 * 2048 = $2048000.

2. What is the purpose of using a doubling formula for calculating monthly salary?

The doubling formula is used to calculate exponential growth, which can be applied to salary increases. This formula assumes that the salary will double every month, allowing for quick and simple calculations of future salary projections.

3. Can the doubling formula be used for any type of salary increase?

No, the doubling formula is typically used for calculating salary increases that follow an exponential growth pattern, such as doubling every month. It may not accurately reflect other types of salary increases, such as a fixed percentage increase.

4. Are there any limitations to using the doubling formula for calculating monthly salary?

Yes, there are a few limitations to using the doubling formula. It assumes that the salary will double every month, which may not be realistic for all job positions. Additionally, it does not account for factors such as inflation or performance-based salary increases.

5. How can the doubling formula be adjusted for other scenarios?

If the salary is not doubling every month, the formula can be adjusted by changing the exponent to match the rate of increase. For example, if the salary is increasing by 10% each month, the formula would be monthly salary = starting salary * 1.1^(number of months - 1).

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
994
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
Back
Top