#17939: 我是用if


fdhs_108OuOb (白熊ʕ •ᴥ•ʔ)


我覺得if比較簡單

 

 

char c;

 

if(c=='+')
cout<<a+b<<endl;
else if(c=='-')
cout<<a-b<<endl;
else if(c=='*')
cout<<a*b<<endl;
else if(c=='/')
cout<<a/b<<endl;

 

大概是這樣

#17975: Re:我是用if


freedom501999@gmail.com (帥氣魔方生)


我覺得if比較簡單

 

 

char c;

 

if(c=='+')
cout<<a+b<<endl;
else if(c=='-')
cout<<a-b<<endl;
else if(c=='*')
cout<<a*b<<endl;
else if(c=='/')
cout<<a/b<<endl;

 

大概是這樣

 


有一個東西叫做 switch-case 語法

+ - * / 都是在 ASCII 裡的字元,用這個語法只要判斷一次

多個 if-else 是很慢的