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:

Code :

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.

Re: Need some help with my code...

Quote:

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

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.

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.

Re: Need some help with my code...