operator cannot be applied to a double double

I am creating an array of 20 values in dollars and cents, then create a total of all, then I want to return a list of all values less than 5.00, and then return the average of the values in the array and finally I want to display list of values greater than the average.
I am getting the following error when I try to compile my code:

jGRASP exec: javac -g C:JavaAssignmentsPrices.java

Prices.java:13: operator + cannot be applied to double,double[]
total += prices;
^
Prices.java:19: operator < cannot be applied to double[],double
if (prices < 5.00){
^
Prices.java:27: operator > cannot be applied to double[],double
if (prices > average) {
^
3 errors

----jGRASP wedge2: exit code for process is 1.


Here is my code:
public class Prices
{
public static void main (String[] args)
{
double[] prices = {1.59,8.98,2.56,7.82,9.70,2.85,
1.98,10.80,5.05,12.76,13.20,7.36,4.86,1.25,2.05,2.70,
9.98,4.25,13.05,6.00};
double average;
double total = 0.0;
int i;
for (i = 0; i < 20; i++)
{
total += prices;
}

System.out.println("Sum of all prices: "+total+"
" );
for (i = 0; i < 20; i++)
{
if (prices < 5.00){
System.out.println(prices + " is less than $5.00");
}
}
average = total / (20);
System.out.println("
The average price is " + average + "
");
for (i = 0; i < 20; i++)
{
if (prices > average) {
System.out.println(prices + " is greater than the average");
}
}
}
}

I am new to java and any helpwould be greatly appreciated.


----jGRASP: operation com

Comments

  • Hey,
    Simple problem to fix. There are five locations in the program where the statement requires a number, i.e. an [color=Blue]element[/color] of the array, but an array is being used.
    The syntax to reference an array element is:
    [code]prices[i][/code]

    regards
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion