/* C Programming, Project 4 */
/* Author: 施佑達 A9228450 */
#include <stdio.h>
#include <stdlib.h>
int main()
{
/* B是指哥哥,S是指弟弟,up是指向上,down是指向下
effect是指影響度,enent是指結果,high是指井高,day是指天數 */
float B_up,B_down,B_effect,B_event=0;
float S_up,S_down,S_effect,S_event=0;
float high;
int day;
printf("請輸入井高:");
scanf("%f",&high);
printf("請輸入蝸牛哥哥的資料\n");
printf("向上:");
scanf("%f",&B_up);
printf("向下:");
scanf("%f",&B_down);
printf("疲勞影響度:");
scanf("%f",&B_effect);
printf("請輸入蝸牛弟弟的資料\n");
printf("向上:");
scanf("%f",&S_up);
printf("向下:");
scanf("%f",&S_down);
printf("黏液影響度:");
scanf("%f",&S_effect);
for(day=1;day<=20;day++)
{
B_event = B_event+(B_up-B_effect*(day-1));
if (B_event >= high) {
printf("在第%d天,哥哥爬到頂!!!\n",day);
break;
}
B_event = B_event-B_down;
if (B_event <= 0.1){
printf("在第%d天,哥哥失敗滑回底!!!\n",day);
break;
}
}
for(day=1;day<=20;day++)
{
S_event = S_event+S_up;
if (S_event >= high) {
printf("在第%d天,弟弟爬到頂!!!\n",day);
break;
}
S_event = S_event-(S_down+S_effect*(day-1));
if (S_event <= 0.1){
printf("在第%d天,弟弟失敗滑回底!!!\n",day);
break;
}
}
system("pause");
return 0;
}
作業四題目
回到首頁
沒有留言:
張貼留言