【发布时间】:2015-07-20 19:40:52
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//You are in the elevator now;
//Define variables;
char a;
char b;
//Ask questions;
printf("You are in the elevator now.\nPlease enter which floor you want to visit?\nPress 'L' for Basement, '1' for 1st floor, '2' for 2nd floor, and '3' for 3rd floor:\n");
scanf("%c", &a);
//Display options;
if (a=='L'){
printf("You are at the basement now.\n", a);
scanf("%c", &b);
printf("Where do you want to go?\nOnly Option is 'P' for Parking lot:\n");
else (b=='P')
printf("You are in the Parking Lot now.\n", b);
}
else if (a=='1')
printf("You are at the main floor now.\n", a);
else if (a=='2')
printf("You are at the Mechanical Department now.\n", a);
else if (a=='3')
printf("You are at the Electrical Department now.\n", a);
else{
printf("It's not an option\n");
}
}
对于用户选择 P 后的第一个选项 L,我得到命令未找到。我应该得到你现在在停车场。我不确定是什么原因造成的。
【问题讨论】:
-
很抱歉我多次提出问题
-
我的电脑有问题
-
你为什么一直添加随机编辑?
-
抱歉系统不让我上传问题
-
您的随机缩进使您的代码难以阅读。第二个
scanf和它下面的printf应该缩进,并且所有内容都应该对齐。