Calculating Monthly Salary with Doubling Formula

  • Thread starter Thread starter remaan
  • Start date Start date
  • Tags Tags
    Formula Salary
Click For Summary

Discussion Overview

The discussion revolves around a programming homework problem that involves calculating a person's monthly salary based on a doubling formula. The salary starts at $1 on the first day and doubles each subsequent day, with participants exploring how to implement this calculation in code.

Discussion Character

  • Homework-related
  • Mathematical reasoning
  • Technical explanation

Main Points Raised

  • One participant presents an initial code attempt but struggles with accumulating the total salary over the month.
  • Another participant suggests calculating the salary for each day and maintaining a running total, implying a step-by-step approach.
  • A question arises about the meaning of "running total," leading to clarification on initializing a total variable and updating it daily.
  • Further confirmation is provided that the total should be updated by adding the current day's salary to the previous total.
  • A participant expresses gratitude after completing their task, indicating progress in understanding the problem.

Areas of Agreement / Disagreement

Participants generally agree on the approach to calculating the total salary, with some clarifications made regarding the implementation details. However, there are no explicit disagreements noted in the discussion.

Contextual Notes

Some participants mention the potential for very large numbers due to the exponential growth of the salary, which may require consideration of data types in programming.

Who May Find This Useful

This discussion may be useful for students learning about loops and accumulators in programming, particularly in the context of mathematical problems involving exponential growth.

remaan
Messages
132
Reaction score
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
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.
 
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 ??
 
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.
 
alright, thanks a lot!

I am done with one right now,

Thanks a lot once again =)
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K