- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int ascii, option;
- char letter;
- cout<<"(1)ascii轉字元 (2)字元轉ascii (3)結束"<<endl;
- cout<<"請選擇: ";
- cin>>option;
- switch(option)
- {
- case 1:
- cout<<"輸入ascii: ";
- cin>>ascii;
- cout<<"ascii碼"<<ascii<<"所對應的字元為: "<<char(ascii)<<endl;
- break;
- case 2:
- cout<<"輸入字元: ";
- cin>>letter;
- cout<<"字元"<<letter<<"所對應的ascii碼為: "<<int(letter)<<endl;
- break;
- case 3:
- goto end;
- break;
- default:
- cout<<"輸入錯誤!"<<endl;
- }
- goto re;
- end:
- system("pause");
- return 0;
- }
複製代碼 |