我对 C 编码(以及一般编码)是全新的,所以我一直在练习一些随机程序。这个应该根据用户的年龄和所需的“区域”数量(他们想去多远)来确定交通票的成本(Translink Vancouver 价格)。我已经成功编译它,但由于某种我无法弄清楚的原因,scanf 函数被忽略了。我该如何解决?请记住,我只编码了几天。谢谢!
int main(void) {
int zones;
int age;
double price = 0.00;
printf("Welcome to TransLink cost calculator!\n\n");
printf("Please enter the desired number of zones (1, 2, or 3) you wish to travel: ");
scanf("%d", &zones);
if (zones < 1) {
printf("Invalid entry\n");
price = 0.00;
}
else if (zones > 3) {
printf("Invalid entry\n");
price = 0.00;
}
else if (zones == 1) {
printf("Please enter your age: ");
scanf("%d", &age);
if (age < 0.00) {
printf("Invalid Aage");
}
else if (age < 5) {
price = 1.95;
}
else if (age >= 5) {
price = 3.00;
}
}
else if (zones == 2) {
printf("Please enter your age: ");
scanf("%d", &age);
if (age < 0) {
printf("Invalid Aage");
}
else if (age < 5) {
price = 2.95;
}
else if (age >= 5) {
price = 4.25;
}
}
else if (zones == 3) {
printf("Please enter your age: ");
scanf("%d", &age);
if (age < 0) {
printf("Invalid Aage");
}
else if (age < 5) {
price = 3.95;
}
else if (age >= 5) {
price = 4.75;
}
}
printf("The price of your ticket is: $%.2f + tax\n", price);
system("PAUSE");
return 0;
}