i trying call method gascost main method. give user choice of entering number bring calculation, in instance user has selected option 3. integer gallons_gas defined in main method, passing gascost method.
i error after else statement , can't compile. says .class expected variable name gallons_gas starts , after gallons_gas says ; expected. doing wrong , how fix this?
public class deryck_hw2_tripcalculatormenu
{
public static void main(string[] args) { //get scanner instance scanner userinput = new scanner(system.in); //ask gallons of gas consumed system.out.print("gallons of gas consumed: "); //save gallons of gas consumed int gallons_gas = userinput.nextint(); //give user options menu menu(); //ask user choice system.out.print("choose options above (enter number 1-4): "); //get user choice 1-4 int choice = userinput.nextint(); //test choice if (choice == 1) { //avgspeed(); } else if (choice == 2) { //mpg(); } else if (choice == 3) { gascost(int gallons_gas); } else { system.out.print("error: selection invalid. restart program , enter number between 1 , 4."); } } public static void gascost(int gallons_gas) { //get scanner instance scanner userinput = new scanner(system.in); //ask cost of gallon of gas system.out.print("what cost per gallon of gas? "); //save cost per gallon double gallon_cost = userinput.nextdouble(); //calculate total cost double total_cost = (gallons_gas * gallon_cost); system.out.print("total cost of gas trip $" + total_cost); }
gascost(int gallons_gas);
should be
int gallons_gas; if (...) { gascost(gallons_gas); }
you cannot declare int within parameter list of method call.
Comments
Post a Comment