Skip to content

Instantly share code, notes, and snippets.

@ruyut
Created March 27, 2019 14:02
Show Gist options
  • Save ruyut/3073f0520858c60459cd48726a5313dc to your computer and use it in GitHub Desktop.
Save ruyut/3073f0520858c60459cd48726a5313dc to your computer and use it in GitHub Desktop.
//802
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
int main() {
char choice[5];//宣告choice是一個字元陣列,長度為5
int a = 0;//宣告a是一個整數,預設值為0
while (a != 5) {//條件成立時執行 如果a不等於5就執行
printf("(1)教授\n(2)副教授\n(3)助理教授\n(4)都不是\n(5)結束\n請輸入您的職稱代號:");//列印
gets(choice);//取得使用者的輸入字串
a = atoi(choice);//atoi() 把括號內的值轉成整數,如果無法轉換就傳回0
switch (a)//條件式判斷
{
case 1: printf("\n您的職稱是教授\n"); break;//如果a=1
case 2: printf("\n您的職稱是副教授\n"); break;//如果a=2
case 3: printf("\n您的職稱是助理教授\n"); break;//如果a=3
case 5: break;//如果a=5
default: printf("\n您的職稱沒有在這些選項內\n");//如果都不是上面的選項的話就
}//break 跳出
}
system("PAUSE");//停住等待使用者按下任意一個按鍵
return 0;//跳出
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment