標題:
switch 判斷式(二) 簡易型計算機
[打印本頁]
作者:
歐柏罕
時間:
2017-10-23 20:31
標題:
switch 判斷式(二) 簡易型計算機
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1 = 0;
float num2 = 0;
char temp; //符號用char
cout<<"請輸入數字1: ";
cin>>num1;
cout<<"請輸入+-*/ ";
cin>>temp;
cout<<"請輸入數字2: ";
cin>>num2;
switch(temp)
{
case '+': //用 ' 包起來
cout << num1 + num2 << endl;
break;
case '-':
cout<<num1 - num2<<endl;
break;
case '*':
cout<<num1 * num2<<endl;
break;
case '/':
cout<<num1 / num2<<endl;
break;
default: // 預設值
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
彭煥宇
時間:
2017-10-23 20:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1=0;
float num2=0;
char temp;
cout<<"請輸入第一個數字:"<<endl;
cin >> num1;
cout<<"請輸入+-*/:"<<endl;
cin >> temp;
cout<<"請輸入第二個數字:"<<endl;
cin >> num2;
switch(temp)
{
case '+':
cout << num1+num2 << endl;
break;
case '-':
cout << num1-num2 << endl;
break;
case '*':
cout << num1*num2 << endl;
break;
case '/':
cout << num1/num2 << endl;
break;
}
system("pause");
return 0;
}
複製代碼
作者:
曾堂桂
時間:
2017-10-23 20:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float number1=0;
float number2=0;
char symbol;
cout<<"請輸入第一個數字:"<<endl;
cin>>number1;
cout<<"請輸入+-*/:"<<endl;
cin>>symbol;
cout<<"請輸入第二個數字:"<<endl;
cin>>number2;
switch(symbol)
{
case '+':
cout<<number1+number2<<endl;
break;
case '-':
cout<<number1-number2<<endl;
break;
case '*':
cout<<number1*number2<<endl;
break;
case '/':
cout<<number1/number2<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
盧佑恩
時間:
2017-10-23 20:36
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1 = 0;
float num2 = 0;
char temp; //符號用char
cout<<"請輸入數字1: ";
cin>>num1;
cout<<"請輸入+-*/ ";
cin>>temp;
cout<<"請輸入數字2: ";
cin>>num2;
switch(temp)
{
case '+': //用 ' 包起來
cout << num1 + num2 << endl;
break;
case '-':
cout<<num1 - num2<<endl;
break;
case '*':
cout<<num1 * num2<<endl;
break;
case '/':
cout<<num1 / num2<<endl;
break;
default: // 預設值
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
沈子晏
時間:
2017-10-23 20:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1= 0;
float num2= 0;
char temp;
cout<<"請輸入第一個數字:"<<endl;
cin>>num1;
cout<<"請輸入+-*/:"<<endl;
cin>>temp;
cout<<"請輸入第二個字:"<<endl;
cin>>num2;
switch(temp)
{
case '+':
cout<<num1+num2<<endl;
break;
case '-':
cout<<num1-num2<<endl;
break;
case '*':
cout<<num1*num2<<endl;
break;
case '/':
cout<<num1/num2<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
盧佑芯
時間:
2017-10-23 20:38
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1 = 0;
float num2 = 0;
char temp;
cout<<"請輸入第一個數字:"<<endl;
cin>>num1;
cout<<"請輸入+-*/"<<endl;
cin>>temp;
cout<<"請輸入第二個數字:"<<endl;
cin>>num2;
switch(temp)
{
case '+':
cout<<num1+num2<<endl;
break;
case '-':
cout<<num1-num2<<endl;
break;
case '*':
cout<<num1*num2<<endl;
break;
case '/':
cout<<num1/num2<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system ("pause");
return 0;
}
複製代碼
作者:
洪翊庭
時間:
2017-10-23 20:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1=0;
float num2=0;
char temp;
cout<<"請輸入第一個數字"<<endl;
cin>>num1;
cout<<"請輸入+-*/"<<endl;
cin>>temp;
cout<<"請輸入第二個數字"<<endl;
cin>>num2;
switch(temp)
{
case'+':
cout<<num1+num2<<endl;
break;
case'-':
cout<<num1-num2<<endl;
break ;
case'*':
cout<<num1*num2<<endl;
break;
case'/':
cout<<num1/num2<<endl;
break ;
}
system("pause");
return 0;
}
複製代碼
作者:
李治毅
時間:
2017-10-23 21:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1 = 0;
float num2 = 0;
char temp;
cout<<"請輸入第一個數字: ";
cin>>num1;
cout<<"請輸入+-*/ ";
cin>>temp;
cout<<"請輸入第二個數字: ";
cin>>num2;
switch(temp)
{
case '+':
cout << num1 + num2 << endl;
break;
case '-':
cout<<num1 - num2<<endl;
break;
case '*':
cout<<num1 * num2<<endl;
break;
case '/':
cout<<num1 / num2<<endl;
break;
default:
cout<<"你輸入錯了"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪翊展
時間:
2017-10-23 21:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1 = 0;
float num2 = 0;
char temp; //符號用char
cout<<"請輸入數字1: ";
cin>>num1;
cout<<"請輸入+-*/ ";
cin>>temp;
cout<<"請輸入數字2: ";
cin>>num2;
switch(temp)
{
case '+': //用 ' 包起來
cout << num1 + num2 << endl;
break;
case '-':
cout<<num1 - num2<<endl;
break;
case '*':
cout<<num1 * num2<<endl;
break;
case '/':
cout<<num1 / num2<<endl;
break;
default: // 預設值
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪啓銓
時間:
2017-10-23 21:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float num1 = 0;
float num2 = 0;
char temp; //符號用char
cout<<"請輸入數字1: ";
cin>>num1;
cout<<"請輸入+-*/ ";
cin>>temp;
cout<<"請輸入數字2: ";
cin>>num2;
switch(temp)
{
case '+': //用 ' 包起來
cout << num1 + num2 << endl;
break;
case '-':
cout<<num1 - num2<<endl;
break;
case '*':
cout<<num1 * num2<<endl;
break;
case '/':
cout<<num1 / num2<<endl;
break;
default: // 預設值
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪啓銓
時間:
2017-10-23 21:02
罕罕老師好
作者:
盧佑恩
時間:
2017-10-30 19:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char ans;
cout<<"題目:123+456=?"<<endl;
cout<<"(A)87 (B)94 (C)9487 (D)579"<<endl;
cin>>ans;
switch(ans)
{
case'a':
case'b':
case'c':
case'A':
case'B':
case'C':
cout<<"答錯!!"<<endl;
break;
case'd':
case'D':
cout<<"答對!!"<<endl;
break;
default:
cout<<"輸入錯誤!!"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2