1

ユーザーに購入したパッケージの数を入力するように求めるプログラムを作成する必要があります。プログラムは、割引額と割引後の合計購入額を表示する必要があります。私はこれを中心にプログラムで設計しました..

import java.util.Scanner;

public class softwareSales
{
   public static void main(String[] args)
   {
      Scanner input = new Scanner(System.in);
      double Package = 99, discount, priceBfDiscount, discountPrice, totalPrice;
      int quantity;

      System.out.println("This is a software sales program");

      System.out.println("Enter number of packages");
      quantity = input.nextInt();

      System.out.println("Enter price of package");
      Package = input.nextDouble();

      System.out.println("Enter gross price");
      priceBfDiscount = input.nextDouble();

      priceBfDisc = Package * quantity;
      discountPrice = priceBfDisc * discount;
      totalPrice = priceBfDisc - discountPrice;

      System.out.println("The price before discount is $" + priceBfDisc);
      System.out.println("The discount price is $" + discountPrice);
      System.out.println("The total price is $" + totalPrice);



      if (quantity >= 10 && quantity <= 19)
      {
         System.out.println("The discount is .20");
      }
      else if (quantity >=20 && quantity <=49)
      {
         System.out.println("The discount is .30");
      }
      else if (quantity >=50 && quantity <=99)
      {
         System.out.println("The discount is .40");
      }
      else if (quantity >=100)
      {
         System.out.println("The discount is .50");
      }  







   }

何が間違いなのかわからない。priceBfDisc にはシンボルがないと言い続けています。誰かが私の間違いを特定するのを手伝ってくれたら、本当に感謝しています。

4

2 に答える 2

8

エラー メッセージを読みます。priceBfDisc;を宣言したことはありません。あなたが宣言しpriceBfDiscountた。

于 2013-10-13T15:27:56.213 に答える
0
double Package = 99, discount, priceBfDiscount, discountPrice, totalPrice;

priceBfDicsこれは、一致しないというエラーに加えて、問題がある場所です。

これらすべての変数を宣言する必要があります

//Either like this
double packageCost;
double discount;
double priceBfDiscount;
double discountPrice,
double total;

// Or like this
double packageCost,discount, priceBfDiscount, discountPrice, total;
于 2013-10-13T15:29:45.857 に答える