當我運行這個,並且我遇到了情況1中表示「輸入颶風#1的最大速度:」的行時,我將輸入「34」並且它將返回「風速在結:25.6789」「輸入颶風#2的最大風速:」但我試圖讓它返回「無效Windspeed爲Hurrican,再試一次。」如果/ else語句在循環內部被忽略
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int x;
int year;
int tropical_storms;
int hurricanes;
int a=1;
int windspeed;
float knots;
float conversion=0.868976;
printf(" HEg v1.0 \n");
printf("0. Exit\n");
printf("1. Submit Hurricane Season Storm Information\n");
printf("2. Submit Storm Data\n");
printf("3. Print Hurricane Season Analysis\n");
printf("4. Print Storm Analysis\n");
printf("\n");
printf("Please Enter Selection: ");
scanf("%d", &x);
switch(x) {
case 0:
printf("Thank you for using HEg v1.0");
break;
case 1:
printf("Enter the year: ");
scanf("%d", &year);
printf("Enter the number of tropical storms in 2009: ");
scanf("%d", &tropical_storms);
printf("Enter the number of Hurricanes in 2009: ");
scanf("%d", &hurricanes);
while(a<=hurricanes){
printf("Enter the max windspeed of hurricane #%d: ", a);
scanf("%d", &windspeed);
a++;
if(windspeed>74){
knots=windspeed*conversion;
printf("Wind speed in knots: %.4f \n", knots);
}
else{
printf("Invalid Windspeed for Hurricane. Try again");
}
}
break;
case 2:
printf("Menu option not available in HEg v1.0");
break;
case 3:
printf("Menu option not available in HEg v1.0");
break;
case 4:
printf("Menu option not available in HEg v1.0");
break;
default:
printf("no");
break;
}
system("PAUSE>nul");
return 0;
}
你爲什麼認爲'if' /'else'語句被忽略? – 2014-09-26 01:54:12
作爲一名經驗豐富的程序員,我可以向您保證,if語句不會被忽略:)請更新您的文章,說出*您預期會發生什麼*以及*實際發生了什麼*。還要描述你給了哪些輸入來引起這種行爲。 – 2014-09-26 02:06:06
目前尚不清楚「聲明中的內容」的含義。 – 2014-09-26 02:06:31