Advertisement
LightProgrammer000

Calculdadora_Basica

Jun 14th, 2023
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.11 KB | None | 0 0
  1. // Bibliotecas
  2. import 'dart:io';
  3.  
  4. // Funcao principal
  5. main() {
  6.   // Variaveis
  7.   var opc;
  8.   double a, b;
  9.  
  10.   // Entrada de dados
  11.   stdout.write("# Primeiro valor: ");
  12.   a = double.parse(stdin.readLineSync()!);
  13.  
  14.   stdout.write("# Segundo valor: ");
  15.   b = double.parse(stdin.readLineSync()!);
  16.  
  17.   // Menu
  18.   stdout.writeln("\n# Operacoes matematicas");
  19.   stdout.writeln("# [+] Somar");
  20.   stdout.writeln("# [-] Subtrair");
  21.   stdout.writeln("# [*] Multiplicar");
  22.   stdout.writeln("# [/] Dividir");
  23.   stdout.write("# Opc: ");
  24.   opc = stdin.readLineSync()!;
  25.  
  26.   // Chamada de metodo
  27.   operacao(a, b, opc);
  28. }
  29.  
  30. // Funcao
  31. void operacao(double a, double b, var opc) {
  32.   if (opc == "+") {
  33.     print("\n# Soma: " + (a + b).toStringAsFixed(2));
  34.   } else if (opc == "-") {
  35.     print("\n Subtrair: " + (a - b).toStringAsFixed(2));
  36.   } else if (opc == "*") {
  37.     print("\n# Multiplicar: " + (a * b).toStringAsFixed(2));
  38.   } else if (opc == "/") {
  39.     try {
  40.       print("\n# Dividir: " + (a / b).toStringAsFixed(2));
  41.     } catch (e) {
  42.       //print(e);
  43.     }
  44.   } else {
  45.     print("# Opcao invalida !");
  46.   }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement