I need to make a program that tells me in how many days do i need to work to get a specific sallary.
Step 1)The program needs to ask how much salary I want.
Step 2)The program will give me as an answer how many days I need to work to get the salary.
For each day the salary doubles with 2.
Day 1 = 1 dollar
Day 2 = 2 dollar
day 3 = 4 dollar
.......I can only work for 30 days
I need to calculate how many days it takes to get the salary im asking for.
For 1000000 dollar then I should get 27 days.
What Problem I have with this question is that I have no idea how to make a loop for this. I dont know how to approach this question. Im a totally beginner in this subject. Please someone explain and show how to do this.
You will get 27 days if you use ¢/öre rather than dollars. But that would be 100,000,000öre.
Always start with for (int i ; i < something; i++) ... when writing a loop. You may need to change those figures in special cases, but you don't have such circumstances here.
No, that isn't what you want your program to do. You are right there. Please write down on paper how you would work out how many days it would take to reach a particular salary. You don't need a loop because you can calculate the days by other means.
Yes, I noticed. But your interpretation is valid, just as OP's (and Campbells and mine). But there is a third interpretation, and more aimed towards the very dangerous labour. That is that the salary per day doubles. So that would give the scheme:
1 day work: earnings 1 * 0.01
2 days work: 2 * 0.02
3 days wotk: 3 * 0.04
et cetera. Now, with this scheme, how many days to work to earn 1.000.000?
There are three kinds of actuaries: those who can count, and those who can't.
Junilu Lacar wrote:. . . So I'm not sure the answer of working 27 days to get a salary of 1,000,000 is correct.
No, if you calculate öre/¢ etc., you have to count up to 10⁸ (= 100,000,000). After 27 doublings, we reach 10²⁷öre = 134,217,728 = 1,342,177.28Kr. The first post said $ when it should have read ¢/öre. If you are calculating $/Kr, you pass 1000000 after 20 doublings.
The only explanation that will give 1000000Kr on day 27 is cumulation. The following figures look the same as some Junilu showed us yesterday:-The day's salary is 2⁽ⁿ⁻¹⁾öre/¢. Because we are using binary arithmetic with the repeated doublings, the cumulative salary is 1öre/¢ less than the next day's salary or (2ⁿ) − 1öre/¢. The () are redundant () to remind us of the operator precedences. We reach a cumulative salary of ≥ 1000000Kr on day 27. As those who have done more programming have realised, even if the worker survives beyond day 30, their arithmetic won't.
MR: As I told you yesterday, please go back and write down on paper how you would calculate number of days to reach/exceed 1000000Kr (=100000000öre). Don't look at your computer and especially don't look at this old code; you need to start anew. There is a way of calculating that without using a loop.
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad: