Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Need some help with my code...

1. ## Need some help with my code...

this is the original assignment : The daily sales amount of a company product for seven days is as follows: 175, 225, 0, 200, 325, 275, 60. Write a program so that the average of sales is increased by x units from the 8th day to the 14th day. x = 1 or 2 or 5 or 10 etc.

heres what i got so far:

```
import java.util.Scanner;

public class sales2{
public static void main(String[] args){
Scanner user_Input = new Scanner(System.in);
double []sales = {175, 225, 0, 200, 325, 275, 60};
double sum = 0, avg;
double newSum = 0;
int averageIncrease;
double newSales = 0;

int i, k;

for (i = 0; i < 7; ++i){
sum = sum + sales[i];
System.out.println("sales[" + i + "] = " + sales[i]);
}
avg = sum/i;
System.out.println("average  = " + avg);

for (k = 8; k < 15; k++) {

System.out.println("How much would you like to increase average sales by?");
averageIncrease = user_Input.nextInt();

avg = avg + averageIncrease;

newSum = avg * k ;

newSales = newSum - sum;

System.out.println("New sales for day[" + k + "] = " +newSales);
}

}
}```

Still having a hard time to figure out how to calculate the right amount of sales for days 9-14. I was able to figure out day 8 by subtracting the new sum from the old sum but cant figure out how to get it to subtract the old sum from the first sales array as well as the previous days sorry if this sounds a little confusing.  Reply With Quote

3. ## Re: Need some help with my code...

average of sales is increased by x units from the 8th day to the 14th day. x = 1 or 2 or 5 or 10 etc.
Can you explain the algorithm for computing the desired results. What you have posted does not make sense.
When increased by 1, when by 2, when by 5, when by 10  Reply With Quote

4. ## Re: Need some help with my code...

Ok the problem gives me the the amount of sales for the first seven days. I need to figure out the average of those days which I have done. But then I need to figure out what the amount of sales would be on day 8 - 14 if I increase the total average by a certain amount. For example If i increase the total average by 5 on day eight how much would I need in sales to get the average increased by that amount. Hope this clarifies it a bit.  Reply With Quote

5. ## Re: Need some help with my code...

Sounds like you need to use some algebra to get the required formula for the program to use.

Use a piece of paper and write down the values and work on formulas to compute the values you want.  Reply With Quote

6. ## Re: Need some help with my code...

.  Reply With Quote