Temperature Converter

import 'dart:io';//1

main(List<String> values) {
  print("Enter Temperature in Celsius");//2
  var temperature = double.parse(stdin.readLineSync());//3
  print("Enter your choice\nF for Freneheit \nK for Kelvin");//4
  var choice = stdin.readLineSync();//5
  var result = " ";//6
  switch (choice)//7 {
    case "F":
    case "f":
      result = "Temperature in Fereheit ${(temperature * 9 / 5) + 32} ";//8
      break;
    case "K":
    case "k":
      result = "Temperature in Kelvin ${(temperature + 273.15)}";//9
      break;
    default:
      result = "Sorry!you entered wrong choice"//10
    break;
  }
  print(result);//11
}
  1. import statement for input and out-stream lib for Dart
  2. Instruct to user enter temperature in celsius
  3. Take user input and convert into double and assign to temperature
  4. Instruct to the user for choosing their operator to perform calculations on temperature
  5. Assign user choice to choice variable
  6. Create result var with a blank string
  7. Apply switch case for choice
  8. if choice “F” or “f” then Celsius to Fahrenheit conversion is performed and assigned to result
  9. if choice “K” or “k” then Celsius to Fahrenheit conversion is performed and assigned to result
  10. if choice other than given choices then sorry massage assigned to result
  11. The calculation result is printed on Command prompt

Leave a Reply

Your email address will not be published. Required fields are marked *