I am brand new to coding C (and coding in general) so I have been practicing with some random programs. This one is supposed to determine the cost of a transit ticket (Translink Vancouver prices) based on the user's age and the desired number of "zones" (how far they would like to go). I have compiled it successfully but for some reason which I can not figure out, the scanf functions are being ignored. How do I fix this? Please keep in mind I have only been coding for a few days. Thanks!
int main(void) {
int zones;
int age;
double price = 0.00;
printf("Welcome to TransLink cost calculator!
");
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
");
price = 0.00;
}
else if (zones > 3) {
printf("Invalid entry
");
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
", price);
system("PAUSE");
return 0;
}
See Question&Answers more detail:os