Skip to content

Instantly share code, notes, and snippets.

@goodjack
Last active October 15, 2017 14:32
Show Gist options
  • Save goodjack/a668ffa1826da0a630c36d344e0e9e28 to your computer and use it in GitHub Desktop.
Save goodjack/a668ffa1826da0a630c36d344e0e9e28 to your computer and use it in GitHub Desktop.
20171005 各種觀念混合範例(if/else if/else、&&、||、cin)
#include <iostream>
using namespace std;
int main ()
{
// 這是單行註解,我要開始宣告了!
int dividend = 5, divisor; // 第一個整數是寫死的,是被除數;第二個整數是除數。
cout << "請輸入除數:";
cin >> divisor; // 除數在這裡給使用者輸入儲存
if (divisor > dividend){
cout << "你的除數比被除數大,我還不會處理小數";
} else if (divisor == 0) {
cout << "你輸入的除數是:" << divisor << ",除數不能為零!";
} else if (dividend == 0 || divisor == 1) {
cout << "這麼簡單的算數我不想幫你算欸...";
} else {
cout << dividend << "除以" << divisor << "是" << dividend/divisor << "餘" << dividend%divisor;
}
cout << "程式結束啦,掰掰!";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment