Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So I have this program... Two questions... -how do I define the char source and

ID: 3724762 • Letter: S

Question

So I have this program... Two questions...

-how do I define the char source and destination as a char to be displayed on the last screen? I assume I would have to put some sort of statement under each of the switches, like source_name=Balitmore; but its not working

-the math on the last screen is wrong, how could I fix it?

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
    char source,destination,destination_name,mode,hotel,stay,food,meals;
    char source_name[20];
    int cost,room_charge,meal_charge,total_charges,hotel_charges,food_charges,total_charge;

    //This section will display the user questions
    printf("******************************************");
    printf(" WELCOME TO THE TRIP EXPENSES CALCULATOR ");
    printf("******************************************");
    getchar();
    system("cls");
    printf("ENTER THE SOURCE CITY :");
    printf(" B for Baltimore");
    printf(" C for Chattanooga");
    printf(" N for Nashville");
    printf(" P for Pasadena ");
    scanf(" %s",&source);
    fflush(stdin);
    system("cls");
    printf("ENTER THE DESTINATION CITY");
    printf(" D for Denver");
    printf(" M for Madison");
    printf(" C for Clarksville");
    printf(" K for Knoxville ");
    scanf(" %s",&destination);
    fflush(stdin);
    system("cls");
    printf("ENTER THE MODE OF TRAVEL");
    printf(" A for Air");
    printf(" R for Train");
    printf(" B for Bus ");
    scanf(" %s",&mode);
    fflush(stdin);
    system("cls");
    printf("ENTER THE TYPE OF HOTEL");
    printf(" F for Five Star");
    printf(" T for Three star");
    printf(" O for ordinary ");
    scanf("%s",&hotel);
    fflush(stdin);
    system("cls");
    printf("ENTER THE NUMBER OF DAYS OF STAY ");
    scanf(" %s",&stay);
    system("cls");
    printf("ENTER THE TYPE OF FOOD");
    printf(" V for Veg");
    printf(" N for normal food");
    printf(" C for Continental ");
    scanf(" %s",&food);
    fflush(stdin);
    system("cls");
    printf("HOW MANY MEALS WOULD YOU BE EATING IN THE HOTEL? ");
    scanf(" %s",&meals);

    //these switches will be to define the transportation cost
    switch(source){
    case'b':case'B':switch(destination){
        case'd':case'D':switch(mode){
                case'a':case'A':cost=5000;
              //source_namr="Balitmore";
                    break;
                case't':case'T':cost=2500;
                    break;
                case'b':case'B':cost=2000;
                    break;}
        case'm':case'M':switch(mode){
                case'a':case'A':cost=4000;
                    break;
                case't':case'T':cost=2000;
                    break;
                case'b':case'B':cost=1000;
                    break;}
        case'k':case'K':switch(mode){
                case'a':case'A':cost=5000;
                    break;
                case't':case'T':cost=2500;
                    break;
                case'b':case'B':cost=2000;
                    break;}
        case'c':case'C':switch(mode){
                case'a':case'A':cost=2500;
                    break;
                case't':case'T':cost=800;
                    break;
                case'b':case'B':cost=1000;
                    break;}
        }//end switch for destination for Balitmore
    case'c':case'C':
        switch(destination){
        case'd':case'D':switch(mode){
                case'a':case'A':cost=2500;
                    break;
                case't':case'T':cost=500;
                    break;
                case'b':case'B':cost=600;
                    break;}
        case'm':case'M':switch(mode){
                case'a':case'A':cost=4000;
                    break;
                case't':case'T':cost=2300;
                    break;
                case'b':case'B':cost=1300;
                    break;}
        case'k':case'K':switch(mode){
                case'a':case'A':cost=4000;
                    break;
                case't':case'T':cost=1600;
                    break;
                case'b':case'B':cost=1400;
                    break;}
        case'c':case'C':switch(mode){
                case'a':case'A':cost=6000;
                    break;
                case't':case'T':cost=2000;
                    break;
                case'b':case'B':cost=1700;
                    break;}
        }//end switch for destination for Chattanooga
    case'n':
    case'N':
        switch(destination){
        case'd':case'D':switch(mode){
                case'a':case'A':cost=5000;
                    break;
                case't':case'T':cost=1500;
                    break;
                case'b':case'B':cost=1400;
                    break;}
        case'm':case'M':switch(mode){
                case'a':case'A':cost=2500;
                    break;
                case't':case'T':cost=900;
                    break;
                case'b':case'B':cost=700;
                    break;}
        case'k':case'K':switch(mode){
                case'a':case'A':cost=4000;
                    break;
                case't':case'T':cost=1500;
                    break;
                case'b':case'B':cost=1000;
                    break;}
        case'c':case'C':switch(mode){
                case'a':case'A':cost=1300;
                    break;
                case't':case'T':cost=1700;
                    break;
                case'b':case'B':cost=1300;
                    break;}
        }//end switch for destination for Nashville
    case'p':case'P':switch(destination){
        case'd':case'D':switch(mode){
                case'a':case'A':cost=5000;
                    break;
                case't':case'T':cost=2000;
                    break;
                case'b':case'B':cost=1400;
                    break;}
        case'm':case'M':switch(mode){
                case'a':case'A':cost=4500;
                    break;
                case't':case'T':cost=1900;
                    break;
                case'b':case'B':cost=1300;
                    break;}
        case'k':case'K':switch(mode){
                case'a':case'A':cost=3000;
                    break;
                case't':case'T':cost=1200;
                    break;
                case'b':case'B':cost=800;
                    break;}
        case'c':case'C':switch(mode){
                case'a':case'A':cost=4500;
                    break;
                case't':case'T':cost=1700;
                    break;
                    case'b':case'B':cost=1300;
                    break;}
        }//end switch for destination for Pasadena
        }//end of switch to define transportation costs
    switch(hotel){
        case'f':case'F':room_charge=500;
            break;
        case't':case'T':room_charge=300;
            break;
        case'o':case'O':room_charge=100;
            break;}//This ends the switch to define the room costs
    switch(food){
        case'v':case'V':meal_charge=15;
            break;
        case'n':case'N':meal_charge=30;
            break;
        case'c':case'C':meal_charge=10;
            break;}//this ends the switch to define food costs


//This next section will include a bunch of calculations
hotel_charges=stay*room_charge;
food_charges=meals*meal_charge;
total_charges=cost+hotel_charges+food_charges;


//This next section will include the last screen to be displayed
system("cls");
printf("****************************************** ");
printf("TOTAL EXPENSES TO TRAVEL FROM %s TO %s ",source_name,destination_name);
printf("****************************************** ");
printf(" TRANSPORTATION CHARGES = %d ",cost);
printf("NUMBER OF DAYS OF STAY = %d ",stay);
printf("NUMBER OF MEALS IN A DAY = %d ",meals);
printf("ROOM CHARGES = %d ",hotel_charges);
printf("FOOD CHARGES = %d ",food_charges);
printf("HOTEL CHARGES = %d ",hotel_charges);
printf("***************************************** ");
printf("TOTAL CHARGES %d ",total_charge);
printf("****************************************** ");

return 0;
}

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main()

{

char source, destination, destination_name, mode, hotel, food;

int stay, meals;

char source_name[20];

int cost, room_charge, meal_charge, total_charges, hotel_charges, food_charges, total_charge;

//This section will display the user questions

printf("******************************************");

printf(" WELCOME TO THE TRIP EXPENSES CALCULATOR ");

printf("******************************************");

getchar();

//system("cls");

printf("ENTER THE SOURCE CITY :");

printf(" B for Baltimore");

printf(" C for Chattanooga");

printf(" N for Nashville");

printf(" P for Pasadena ");

scanf("%c", &source);

fflush(stdin);

system("cls");

printf("ENTER THE DESTINATION CITY");

printf(" D for Denver");

printf(" M for Madison");

printf(" C for Clarksville");

printf(" K for Knoxville ");

scanf(" %c", &destination);

fflush(stdin);

system("cls");

printf("ENTER THE MODE OF TRAVEL");

printf(" A for Air");

printf(" R for Train");

printf(" B for Bus ");

scanf(" %c", &mode);

fflush(stdin);

system("cls");

printf("ENTER THE TYPE OF HOTEL");

printf(" F for Five Star");

printf(" T for Three star");

printf(" O for ordinary ");

scanf(" %c", &hotel);

fflush(stdin);

system("cls");

printf("ENTER THE NUMBER OF DAYS OF STAY ");

scanf(" %d", &stay);

system("cls");

printf("ENTER THE TYPE OF FOOD");

printf(" V for Veg");

printf(" N for normal food");

printf(" C for Continental ");

scanf(" %c", &food);

fflush(stdin);

system("cls");

printf("HOW MANY MEALS WOULD YOU BE EATING IN THE HOTEL? ");

scanf(" %d", &meals);

//these switches will be to define the transportation cost

switch (source)

{

case 'b':

case 'B':

switch (destination)

{

case 'd':

case 'D':

switch (mode)

{

case 'a':

case 'A':

cost = 5000;

//source_namr="Balitmore";

break;

case 't':

case 'T':

cost = 2500;

break;

case 'b':

case 'B':

cost = 2000;

break;

}

case 'm':

case 'M':

switch (mode)

{

case 'a':

case 'A':

cost = 4000;

break;

case 't':

case 'T':

cost = 2000;

break;

case 'b':

case 'B':

cost = 1000;

break;

}

case 'k':

case 'K':

switch (mode)

{

case 'a':

case 'A':

cost = 5000;

break;

case 't':

case 'T':

cost = 2500;

break;

case 'b':

case 'B':

cost = 2000;

break;

}

case 'c':

case 'C':

switch (mode)

{

case 'a':

case 'A':

cost = 2500;

break;

case 't':

case 'T':

cost = 800;

break;

case 'b':

case 'B':

cost = 1000;

break;

}

} //end switch for destination for Balitmore

case 'c':

case 'C':

switch (destination)

{

case 'd':

case 'D':

switch (mode)

{

case 'a':

case 'A':

cost = 2500;

break;

case 't':

case 'T':

cost = 500;

break;

case 'b':

case 'B':

cost = 600;

break;

}

case 'm':

case 'M':

switch (mode)

{

case 'a':

case 'A':

cost = 4000;

break;

case 't':

case 'T':

cost = 2300;

break;

case 'b':

case 'B':

cost = 1300;

break;

}

case 'k':

case 'K':

switch (mode)

{

case 'a':

case 'A':

cost = 4000;

break;

case 't':

case 'T':

cost = 1600;

break;

case 'b':

case 'B':

cost = 1400;

break;

}

case 'c':

case 'C':

switch (mode)

{

case 'a':

case 'A':

cost = 6000;

break;

case 't':

case 'T':

cost = 2000;

break;

case 'b':

case 'B':

cost = 1700;

break;

}

} //end switch for destination for Chattanooga

case 'n':

case 'N':

switch (destination)

{

case 'd':

case 'D':

switch (mode)

{

case 'a':

case 'A':

cost = 5000;

break;

case 't':

case 'T':

cost = 1500;

break;

case 'b':

case 'B':

cost = 1400;

break;

}

case 'm':

case 'M':

switch (mode)

{

case 'a':

case 'A':

cost = 2500;

break;

case 't':

case 'T':

cost = 900;

break;

case 'b':

case 'B':

cost = 700;

break;

}

case 'k':

case 'K':

switch (mode)

{

case 'a':

case 'A':

cost = 4000;

break;

case 't':

case 'T':

cost = 1500;

break;

case 'b':

case 'B':

cost = 1000;

break;

}

case 'c':

case 'C':

switch (mode)

{

case 'a':

case 'A':

cost = 1300;

break;

case 't':

case 'T':

cost = 1700;

break;

case 'b':

case 'B':

cost = 1300;

break;

}

} //end switch for destination for Nashville

case 'p':

case 'P':

switch (destination)

{

case 'd':

case 'D':

switch (mode)

{

case 'a':

case 'A':

cost = 5000;

break;

case 't':

case 'T':

cost = 2000;

break;

case 'b':

case 'B':

cost = 1400;

break;

}

case 'm':

case 'M':

switch (mode)

{

case 'a':

case 'A':

cost = 4500;

break;

case 't':

case 'T':

cost = 1900;

break;

case 'b':

case 'B':

cost = 1300;

break;

}

case 'k':

case 'K':

switch (mode)

{

case 'a':

case 'A':

cost = 3000;

break;

case 't':

case 'T':

cost = 1200;

break;

case 'b':

case 'B':

cost = 800;

break;

}

case 'c':

case 'C':

switch (mode)

{

case 'a':

case 'A':

cost = 4500;

break;

case 't':

case 'T':

cost = 1700;

break;

case 'b':

case 'B':

cost = 1300;

break;

}

} //end switch for destination for Pasadena

} //end of switch to define transportation costs

switch (hotel)

{

case 'f':

case 'F':

room_charge = 500;

break;

case 't':

case 'T':

room_charge = 300;

break;

case 'o':

case 'O':

room_charge = 100;

break;

} //This ends the switch to define the room costs

switch (food)

{

case 'v':

case 'V':

meal_charge = 15;

break;

case 'n':

case 'N':

meal_charge = 30;

break;

case 'c':

case 'C':

meal_charge = 10;

break;

} //this ends the switch to define food costs

//This next section will include a bunch of calculations

hotel_charges = stay * room_charge;

food_charges = meals * meal_charge;

total_charges = cost + hotel_charges + food_charges;

//This next section will include the last screen to be displayed

system("cls");

printf("****************************************** ");

printf("TOTAL EXPENSES TO TRAVEL FROM %s TO %s ", source_name, destination_name);

printf("****************************************** ");

printf(" TRANSPORTATION CHARGES = %d ", cost);

printf("NUMBER OF DAYS OF STAY = %d ", stay);

printf("NUMBER OF MEALS IN A DAY = %d ", meals);

printf("ROOM CHARGES = %d ", hotel_charges);

printf("FOOD CHARGES = %d ", food_charges);

printf("HOTEL CHARGES = %d ", hotel_charges);

printf("***************************************** ");

printf("TOTAL CHARGES %d ", total_charges);

printf("****************************************** ");

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote