I have problem in this code, this code can not be executed. Here is the code:
import 'dart:io';
main() {
print("CALCULATOR");
stdout.write("Number a: ");
double a = double.parse(stdin.readLineSync());
stdout.write("Number b: ");
double b = double.parse(stdin.readLineSync());
double result;
// operator +
result = a + b;
print("$a + $b = $result");
// operator -
result = a - b;
print("$a - $b = $result");
// operator *
result = a * b;
print("$a * $b = $hasil");
// operator /
result = a / b;
print("$a / $b = $result");
// operator %
result = a % b;
print("$a % $b = $result");
}
This my problem:
myLearning/myNote/test.dart:7:33: Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
double a = double.parse(stdin.readLineSync());
^
myLearning/myNote/test.dart:9:33: Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
double b = double.parse(stdin.readLineSync());
I just want if I input a number the result will be like this:
CALCULATOR
Number a : 9
Number b : 2
9.0 + 2.0 = 11.0
9.0 - 2.0 = 7.0
9.0 * 2.0 = 18.0
9.0 / 2.0 = 4.5
9.0 % 2.0 = 1.0
can I get input like the one above?