J
JeffJak
why my scripts is wrong, i have declare the cost..why i still got
error
// How much it cost for the gas to be consumed per cubic meter
import java.util.Scanner;
public class GasCharge
{
public static void main(String[] args)
{
// Declare constants and variables
double cost;
double gas;
// Read input
Scanner scn = new Scanner(System.in);
System.out.print("The amount of gas consumed in cubic
meters:");
gas = scn.nextDouble();
// Selection Structure
if (gas <= 100)
cost = 5.00;
else
if (gas <=300)
cost = gas * 0.4;
else
if (gas <= 500)
cost = gas * 0.2;
else
if (gas > 500)
cost = gas * 0.1;
// Display output (result)
System.out.println ("The total cost is($):" +cost);
}
}
ERROR->
GasCharge.java:32: variable cost might not have been initialized
System.out.println ("The total cost is($):" +cost);
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Thanks in advance...=)
error
// How much it cost for the gas to be consumed per cubic meter
import java.util.Scanner;
public class GasCharge
{
public static void main(String[] args)
{
// Declare constants and variables
double cost;
double gas;
// Read input
Scanner scn = new Scanner(System.in);
System.out.print("The amount of gas consumed in cubic
meters:");
gas = scn.nextDouble();
// Selection Structure
if (gas <= 100)
cost = 5.00;
else
if (gas <=300)
cost = gas * 0.4;
else
if (gas <= 500)
cost = gas * 0.2;
else
if (gas > 500)
cost = gas * 0.1;
// Display output (result)
System.out.println ("The total cost is($):" +cost);
}
}
ERROR->
GasCharge.java:32: variable cost might not have been initialized
System.out.println ("The total cost is($):" +cost);
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Thanks in advance...=)