import java.util.Scanner;
import javax.swing.JOptionPane;
public class RestaurantBill3
{
public static void main(String [] args)
{
//Constant
final double TAX_RATE = 0.0675;
final double TIP_PERCENT = 0.15;
//Variables
double cost;
double taxAmount = TAX_RATE * cost; //Tax amount
double totalWTax = taxAmount + cost; //Total with tax
double tipAmount = TIP_PERCENT * totalWTax; //Tip amount
double totalCost = taxAmount + tipAmount + totalWTax; //Total cost of meal
Scanner keyboard = new Scanner(System.in);
System.out.print("What is the cost of your meal? ");
cost = keyboard.nextDouble();
System.out.println("Your meal cost $" +cost);
System.out.println("Your Tax is $" + taxAmount);
System.out.println("Your Tip is $" + tipAmount);
System.out.println("The total cost of your meal is $" + totalCost);
System.exit(0); //End program
}
}
/* 我不断收到错误成本显然没有被初始化,但如果它等待输入,它是如何应该做的?*/餐馆账单,初始化错误
在分配任何值之前,您正在计算中使用'cost'。首先为其分配一个值。 – Kon 2015-02-10 21:40:56