I need help with this program, so basically, it is suppose to ask for information of a flight and produce air mile points accordingly. I can't seem to make this program work correctly. When birth_month == travel_month, the question if the day is saturday or tuesday is not suppose to display, or have a prompt after wards, but it does and the bonus for traveling on a saturday is always included even if I input n.
Please help, I just started programming and I've been at this for a long time and I can't get it to work and don't know what the problem is...the compiler I am using is on matrix but I'm not sure what that is. I've been told that its similar to borland.
Code:
#include <stdio.h>
main () {
/*Variables are getting initiated*/
int km, class, birth_month, travel_month, base_points, bonus_birth = 0, bonus_saturday = 0, bonus_tuesday = 0, tot = 0;
char saturday, tuesday;
printf ("Welcome to Jet Lag Airlines!\n");
printf ("Enter the distance travelled in km: ");
scanf ("%d", &km); /*Prompts user to input distance travelled in km*/
printf ("\nEnter the class of travel (1-Economy, 2-Business, 3-First Class): ");
scanf ("%d", &class); /*Prompts user to input the class of their ticket*/
/*Checks if the km travelled is less or more than 1000km and which class th*/
if (km <= 1000 && class == 1) {
base_points = 1000;
}
else if (km <= 1000 && class == 2) {
base_points = 2000;
}
else if (km <= 1000 && class == 3) {
base_points = 3000;
}
else if (km > 1000 && class == 1) {
base_points = km;
}
else if (km > 1000 && class == 2) {
base_points = km * 2;
}
else {
base_points = km * 3;
}
printf ("\nIn which month were you born (1-Jan, 2-Feb, ..., 12-Dec): ");
scanf ("%d", &birth_month);
printf ("\nIn which month did travel take place (1-Jan, 2-Feb, ..., 12-Dec): ");
scanf ("%d", &travel_month);
if (birth_month == travel_month) {
bonus_birth = base_points * 2;
}
while (getchar() != '\n') continue;
if (birth_month != travel_month) {
printf ("\nWas travel on a Saturday (Y-Yes, N-No): ");
scanf ("%c", &saturday);
}
while (getchar() != '\n') continue;
if (saturday == 'n' || 'N' && birth_month != travel_month) {
printf ("\nWas travel on a Tuesday (Y-Yes, N-No): ");
scanf ("%c", &tuesday);
}
if (saturday == 'y' || 'Y' && birth_month != travel_month) {
bonus_saturday = base_points * 1.5;
}
else if (tuesday == 'y' || 'Y' && birth_month != travel_month) {
bonus_tuesday = base_points;
}
tot = base_points + bonus_birth + bonus_saturday + bonus_tuesday;
printf ("\nSummary of points awarded:\n");
printf ("==============================================\n");
printf ("Base points: \t\t\t\t%d", base_points);
printf ("\nBonus for birth month: \t\t\t%d", bonus_birth);
printf ("\nBonus for Saturday travel: \t\t%d", bonus_saturday);
printf ("\nBonus for Tuesday travel: \t\t%d", bonus_tuesday);
printf ("\n==============================================\n");
printf ("Total points: \t\t\t\t%d", tot);
if (tot >= 5000) {
printf ("\nCongratulations! You have enough points to redeem for a reward.\n");
}
else {
printf("\nNot enough to redeem for a reward.\n");
}
}