Here is a simple calculator program in Dart that can perform basic arithmetic operations:
import 'dart:io';
void main(){
print('1.Addtion\n 2.Subraction\n 3.Multiplication\n 4.Divisions');
print('Enter your chooice:');
int a,b;
int choice=int.parse(stdin.readLineSync()!);
switch(choice){
case 1:{
print('Enter first number;');
a=int.parse(stdin.readLineSync()!);
print('Enter second number:');
b=int.parse(stdin.readLineSync()!);
print('The sum is : ${a+b}');
break;
}
case 2:{
print('Enter first number;');
a=int.parse(stdin.readLineSync()!);
print('Enter second number:');
b=int.parse(stdin.readLineSync()!);
print('The sum is : ${a-b}');
break;
}
case 3:{
print('Enter first number;');
a=int.parse(stdin.readLineSync()!);
print('Enter second number:');
b=int.parse(stdin.readLineSync()!);
print('The sum is : ${a*b}');
break;
}
case 4:{
print('Enter first number;');
a=int.parse(stdin.readLineSync()!);
print('Enter second number:');
b=int.parse(stdin.readLineSync()!);
print('The sum is : ${a/b}');
break;
}
default:{
print('please enter correct chooice');
}
}}
output:
1.Addtion
2.Subraction
3.Multiplication
4.Divisions
Enter your chooice:
3
3.Multiplication
Enter first number;
2
Enter second number:
4
The sum is : 8
function to display the result of the arithmetic operation to the user.
No comments:
Post a Comment