Untitled
user_4237512
c_cpp
2 years ago
1.2 kB
13
Indexable
#include<iostream>
using namespace std ;
int main(){
int userChoice ;
int num1 ;
int num2 ;
int ans ;
cout << "1代表加,2代表減,3代表乘,4代表除,請輸入數字進入到相應功能中。" << endl ;
cin >> userChoice ;
if(userChoice == 1){
cout << "請輸入想要相加的兩個數。" << endl ;
cin >> num1 ;
cin >> num2 ;
ans = num1 + num2 ;
cout << ans << endl ;
}
if(userChoice == 2 ){
cout << "請輸入想要相減的兩個數。" << endl ;
cin >> num1 ;
cin >> num2 ;
ans = num1 - num2 ;
cout << ans << endl ;
}
if(userChoice == 3){
cout << "請輸入想要相乘的兩個數。" << endl ;
cin >> num1 ;
cin >> num2 ;
ans = num1 * num2 ;
cout << ans << endl ;
}
if(userChoice == 4){
cout << "請輸入想要相除的兩個數。" << endl ;
cin >> num1 ;
cin >> num2 ;
if ( num2 == 0 ){
cout << "除數不可為0" << endl ;
}
else{
ans = num1 / num2 ;
cout << ans << endl ;
}
}
}Editor is loading...