import java.util.Scanner;
import java.lang.Math;
public class cdstore
{
public static void main(String args[])
{
double A = 19.00;
double B = 17.00;
double C = 14.00;
double D = 12.00;
double E = 10.00;
double p;
char z = ' ';
while(z!= 'x')
{
Scanner i = new Scanner(System.in);
System.out.println("Enter Letter");
String l = i.next();
if(l.equals("a") || l.equals("A"))
{p = A;}
else if(l.equals("b") || l.equals("B"))
{p = B;}
else if(l.equals("c") || l.equals("C"))
{p = C;}
else if(l.equals("d") || l.equals("D"))
{p = D;}
else if(l.equals("x") || l.equals("X"))
{System.out.println("subtotal = " + p);}
else
{System.out.println("incorrect value, please try again");}
z = l.charAt(0);
z = Character.toLowerCase(z);
}
}
}
i get an error with
Java question?
Java is quite sensitive with variable declaration
to get rid of the error regarding p
replace the line
double p;
with
double p = 0.0;
to get the subtotal you will need to accumulate the sales
use the ff
p += A;
p += B;
p += C;
p += D;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment