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

حل السؤال

حل السؤال 38

import 'dart:io';
void main() {
  stdout.write('Enter the duration (hours) = ');
  double hours = double.parse(stdin.readLineSync()!);
  if (!hours.isFinite || hours <= 0) {
    print('Invalid input: a finite positive duration required.');
    return;
  }
  double cost = 0;
  if (hours < 1) {
    cost = 5;
  } else if (hours >= 1 && hours < 5) {
    cost = 20;
  } else if (hours >= 5 && hours <= 10) {
    cost = 40;
  } else {
    cost = 40 + (hours - 10) * 0.5;
  }
  print('Your bill: ${cost.toStringAsFixed(2)} \$');
}
العودة إلى السؤال نفسه