Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*************************************/
- /** 20140318 Calculation of Results **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/03/11 pm.11:56 **/
- /*************************************/
- #include <stdio.h>
- #include <stdlib.h>
- void main()
- {
- /*定義變數, 當select 輸入為1 時代表及格, 2 則為不及格
- pass 為及格人數,total 為成績總數 */
- int select = 0, pass = 0, total = 0;
- float pass_percentage = 0;
- printf("Enter score, -1 is exit program.\n");
- //當輸入不等於-1 時執行迴圈
- while(1)
- {
- printf("Enter Number: ");
- scanf("%d", &select);
- if(select != -1)
- {
- total += 1;
- if(select == 1)
- {
- pass += 1;
- }
- }
- else if(select == -1)
- {
- break;
- }
- }
- //已跳出迴圈, 開始計算及格百分率
- //當成績總數等於零, 代表無資料可計算
- if(total == 0)
- {
- printf("No data can calculate");
- }
- else
- {
- //輸出及格人數
- printf("Pass: %d\n", pass);
- //輸出不及格人數(總人數 減去 及格人數)
- printf("Fail: %d\n", total - pass);
- //及格百分率, 利用float(浮點數) 進行運算
- pass_percentage = ((float)pass / total) * 100;
- printf("Pass percentage: %2.2f%%.\n", pass_percentage);
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment