本帖最後由 tonyh 於 2012-5-5 17:07 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int option, ascii;
- char letter;
- start:
- cout<<"1-輸入ASCII碼查詢字元 2-輸入字元查詢ASCII碼 3-結束程式"<<endl;
- cout<<"請選擇: ";
- cin>>option;
- switch(option)
- {
- case 1:
- cout<<"在此輸入ASCII碼: ";
- cin>>ascii;
- cout<<"ASCII碼"<<ascii<<"所對應的字元為"<<char(ascii);
- break;
- case 2:
- cout<<"在此輸入字元: ";
- cin>>letter;
- cout<<"字元"<<letter<<"所對應的ASCII碼為"<<int(letter);
- break;
- case 3:
- goto end;
- break;
- default:
- cout<<"輸入錯誤!";
- }
- cout<<endl<<endl;
- goto start;
- end:
- system("pause");
- return 0;
- }
複製代碼 |