当我运行这个,并且我遇到了情况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