فهرس الكتباللغة البرمجية دارت

حل السؤال

حل السؤال 49

import 'dart:io';
void main() {
  print("****PRODUCT OPTIONS****");
  print("(B or b): Batteries");
  print("(L or l): Lamps");
  print("(F or f): Fuses");
  print("*********************");
  stdout.write("Enter your choice: ");
  String choice = stdin.readLineSync()!.toLowerCase();
  stdout.write("How much $choice will you purchase: ");
  double amount = double.parse(stdin.readLineSync()!);
  double totalCost = 0;
  switch (choice) {
    case "b":
    case "batteries":
      if (amount > 1000) {
        totalCost = amount * 0.90;
      } else {
        totalCost = amount;
      }
      break;
    case "l":
    case "lamps":
      if (amount > 500) {
        totalCost = amount * 0.92;
      } else {
        totalCost = amount;
      }
      break;
    case "f":
    case "fuses":
      if (amount > 100) {
        totalCost = amount * 0.95;
      } else {
        totalCost = amount;
      }
      break;
    default:
      print("Invalid product choice.");
      return;
  }
  print("Payment = $totalCost");
}
العودة إلى السؤال نفسه