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

حل السؤال

حل السؤال 45

import 'dart:io';
void main() {
  stdout.write("Enter the first number: ");
  double num1 = double.parse(stdin.readLineSync()!);
  stdout.write("Enter the second number: ");
  double num2 = double.parse(stdin.readLineSync()!);
  print("Choose the operation you want to perform: ");
  print("1- Addition");
  print("2- Subtraction");
  print("3- Multiplication");
  print("4- Division");
  int choice = int.parse(stdin.readLineSync()!);
  switch (choice) {
    case 1:
      double sum = num1 + num2;
      print("Addition: $num1 + $num2 = $sum");
      break;
    case 2:
      double subtraction = num1 - num2;
      print("Subtraction: $num1 - $num2 = $subtraction");
      break;
    case 3:
      double multiply = num1 * num2;
      print("Multiplication: $num1 * $num2 = $multiply");
      break;
    case 4:
      if (num2 != 0) {
        double division = num1 / num2;
        print("Division: $num1 / $num2 = $division");
      } else {
        print("Cannot divide by zero.");
      }
      break;
    default:
      print("Invalid input");
  }
}
العودة إلى السؤال نفسه