文章出處

源代碼:

#include<stdio.h>
#include<stdlib.h>
main()
{int a,b,op,os;
printf(" [每課一練 媽媽再也不用擔心我的學習]\n");
aq1: printf("選擇您想挑戰的運算法則\n");
printf("1.加法 2.減法 3.乘法 4.除法\n");
scanf("%d",&op);
switch(op)
{
aq: case 1:
a=rand();b=rand();
printf("題目為:%d + %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一題\n");
scanf("%d",&os);
if(os==1)
{printf("%d + %d =%d\n\n\n",a,b,a+b);
goto aq1;
}
else
goto aq;
break;
at: case 2:a=rand();b=rand();
printf("題目為:%d - %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一題\n");
scanf("%d",&os);
if(os==1)
{printf("%d - %d =%d\n\n\n",a,b,a-b);
goto aq1;
}
else
goto at;
break;
aq2: case 3:
a=rand();b=rand();
printf("題目為:%d * %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一題\n");
scanf("%d",&os);
if(os==1)
{printf("%d * %d =%d\n\n\n",a,b,a*b);
goto aq1;
}
else
goto aq2;
aq3: case 4:
a=rand();b=rand();
printf("題目為:%d / %d = ?\n\n",a,b);
printf("1.查看答案 2.做下一題\n");
scanf("%d",&os);
if(os==1)
{printf("%d / %d =%d\n\n\n",a,b,a/b);
goto aq1;
}
else
goto aq3;
break;
}
}

總結:

1.rand()涵數沒有真正實現隨 用srand會更好

2.過多的goto使用 使整體結構破壞

3.沒有設置rand的范圍

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()