// C3_1.cpp : Defines the entry point for the console application. // if - 迴圈應用 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { char data = 0; // 設定初始值 cout << endl << "請輸入一字元 : "; // 提示輸入 cin >> data; // 讀取一字元 if(data >= 'A') // 測試大於等於 'A' if(data <= 'Z') // 測試小於等於 'Z' { cout << endl << " *** 輸入為大寫英文字母。" << endl; cout << " 輸入字母 : " << data << endl // __toascii 函式為字元轉為 ASCII 碼 << " ASCII code : " << __toascii(data) << endl; return 0; } if(data >= 'a') // 測試大於等於 'a' if(data <= 'z') // 測試小於等於 'z' { cout << endl << " *** 輸入為小寫英文字母。" << endl; cout << " 輸入字母 : " << data << endl << " ASCII code : " << __toascii(data) << endl; return 0; } cout << endl << " *** 輸入不為英文字母!" << endl; return 0; }