Need help with a java statement.
Okay here is the assignment. I need to use a for loop to solve this problem.
You are offered two salary options for ten days work. Option 1: $100 per day.
Option 2: $1 for the first day, $2 for the second day, $4 for the third day, and so on,
I have already figured out a way to solve the first portion of the problem. But the 2nd problem is giving me a hard time
Code java:
/**
*
*
* CSC 225 - Online
* Problem 8
*/
import java.text.*;
public class PBS5_8
{
public static void main(String [] args)
{
double optionOne, optionTwo, increment, sum1, sum2;
optionOne = 100;
optionTwo = 1;
sum1 = 0;
sum2 = 0;
for(increment = 1; increment <= 10; )
{
sum1 = sum1 + optionOne;
sum2 = sum2 + optionTwo * 2;
increment++;
}
System.out.println(sum1);
System.out.println(sum2);
}
}
Here is my output!
1000.0
20.0
Okay 20.0 should really be 1023.00 but I don't know how to make the value multiple itself and then add it to the sum. Is there any suggestions? FYI I already written the arithmetic but the coding portion is giving me a hard time.
Re: Need help with a java statement.
Quote:
I already written the arithmetic
Could you post the formulas that you have found?
Write a line for 1 day
and another line for the 2nd day
and another for the 3rd
and see it what the pattern is so you can code it in a loop.
Re: Need help with a java statement.
Okay well its not really a formula. It just notes I wrote down out.
1
2=1*2
4=2*2
8=4*2
16=8*2
etc
The common factor is two but after that I really don't know else to really do. I played with the java for a bit but I just don't know what else to do. Any ideas?
Re: Need help with a java statement.
What about the pattern? Each line takes the results (first column) from the previous line and uses it as the first operand of the expression on the current line.
Re: Need help with a java statement.
Okay.... Yeah i see that but how should I write that in java. I mean here is what I think.
sum2 = sum2+ OptionTwo*2;
It goes through the for loop operation but it never produces any other output except the initial answer.
Re: Need help with a java statement.
Look at the formulas in post#3. There isn't a + operator there.
Write the same style formulas for the statement in post#5 as those in post#3 and see the difference.
Re: Need help with a java statement.
Well I can do that Norm. :confused: But if I do that it will just print out each individual statements instead of adding them and then printing the sum . When I was working on it I realize she wanted the total sum of the two. Not the actual print out of all the integers.
--- Update ---
I know Im missing something but I don't know what.
Re: Need help with a java statement.
There are two parts:
1) multiply last by 2
2) sum the products
Re: Need help with a java statement.
So I should write two parts and then display the sum. I was thinking I could put it under one statement. Is that even possible?
Re: Need help with a java statement.
Take a piece of paper and work out the possibilities.
Re: Need help with a java statement.
okay Ill try that thanks again