I am writing a program that will let the user enter various types of information to calculate the expenses for a vacation trip.
I am given the costs of three different forms of transportation, as well as four source cities and four destination cities.
The three forms of travel are air, train and bus, while the source cities are Baltimore, Chattanooga, Nashville, and Pasadena. The destination cities are Denver, Madison, Clarksville, and Knoxville.
I need to be able to calculate the cost to travel between each source and each destination city depending on what the user enters (form of travel, and each city).
Now, my first guess was to write a very very long if/else if statement for each condition. I tried it and it doesn't seem to work either because it is so long or maybe I messed up somewhere.
if(transportation_type == 'A', 'a' && src_city == 'B', 'b' && dest_city == 'D', 'd')
transportation_price = 5000;
else if(transportation_type == 'A', 'a' && src_city == 'B', 'b' && dest_city == 'M', 'm')
transportation_price = 4000;
else if(transportation_type == 'A', 'a' && src_city == 'B', 'b' && dest_city == 'K', 'k')
transportation_price = 5000;
else if(transportation_type == 'A', 'a' && src_city == 'B', 'b' && dest_city == 'C', 'c')
transportation_price = 2500;
else if(transportation_type == 'T', 't' && src_city == 'B', 'b' && dest_city == 'D', 'd')
transportation_price = 2500;
else if(transportation_type == 'T', 't' && src_city == 'B', 'b' && dest_city == 'M', 'm')
transportation_price = 2000;
else if(transportation_type == 'T', 't' && src_city == 'B', 'b' && dest_city == 'K', 'k')
transportation_price = 2500;
else if(transportation_type == 'T', 't' && src_city == 'B', 'b' && dest_city == 'C', 'c')
transportation_price = 800;
else if(transportation_type == 'B', 'b' && src_city == 'B', 'b' && dest_city == 'D', 'd')
transportation_price = 2000;
else if(transportation_type == 'B', 'b' && src_city == 'B', 'b' && dest_city == 'M', 'm')
transportation_price = 1000;
else if(transportation_type == 'B', 'b' && src_city == 'B', 'b' && dest_city == 'K', 'k')
transportation_price = 2000;
else if(transportation_type == 'B', 'b' && src_city == 'B', 'b' && dest_city == 'C', 'c')
transportation_price = 2000;
else if(transportation_type == 'A', 'a' && src_city == 'C', 'c' && dest_city == 'D', 'd')
transportation_price = 2500;
else if(transportation_type == 'A', 'a' && src_city == 'C', 'c' && dest_city == 'M', 'm')
transportation_price = 4000;
else if(transportation_type == 'A', 'a' && src_city == 'C', 'c' && dest_city == 'K', 'k')
transportation_price = 4000;
else if(transportation_type == 'A', 'a' && src_city == 'C', 'c' && dest_city == 'C', 'c')
transportation_price = 6000;
else if(transportation_type == 'T', 't' && src_city == 'C', 'c' && dest_city == 'D', 'd')
transportation_price = 500;
else if(transportation_type == 'T', 't' && src_city == 'C', 'c' && dest_city == 'M', 'm')
transportation_price = 2300;
else if(transportation_type == 'T', 't' && src_city == 'C', 'c' && dest_city == 'K', 'k')
transportation_price = 1600;
else if(transportation_type == 'T', 't' && src_city == 'C', 'c' && dest_city == 'C', 'c')
transportation_price = 2000;
else if(transportation_type == 'B', 'b' && src_city == 'C', 'c' && dest_city == 'D', 'd')
transportation_price = 600;
else if(transportation_type == 'B', 'b' && src_city == 'C', 'c' && dest_city == 'M', 'm')
transportation_price = 1300;
else if(transportation_type == 'B', 'b' && src_city == 'C', 'c' && dest_city == 'K', 'k')
transportation_price = 1400;
else if(transportation_type == 'B', 'b' && src_city == 'C', 'c' && dest_city == 'C', 'c')
transportation_price = 1700;
else if(transportation_type == 'A', 'a' && src_city == 'N', 'n' && dest_city == 'D', 'd')
transportation_price = 5000;
else if(transportation_type == 'A', 'a' && src_city == 'N', 'n' && dest_city == 'M', 'm')
transportation_price = 2500;
else if(transportation_type == 'A', 'a' && src_city == 'N', 'n' && dest_city == 'K', 'k')
transportation_price = 4000;
else if(transportation_type == 'A', 'a' && src_city == 'N', 'n' && dest_city == 'C', 'c')
transportation_price = 4500;
else if(transportation_type == 'T', 't' && src_city == 'N', 'n' && dest_city == 'D', 'd')
transportation_price = 1500;
else if(transportation_type == 'T', 't' && src_city == 'N', 'n' && dest_city == 'M', 'm')
transportation_price = 900;
else if(transportation_type == 'T', 't' && src_city == 'N', 'n' && dest_city == 'K', 'k')
transportation_price = 1500;
else if(transportation_type == 'T', 't' && src_city == 'N', 'n' && dest_city == 'C', 'c')
transportation_price = 1700;
else if(transportation_type == 'B', 'b' && src_city == 'N', 'n' && dest_city == 'D', 'd')
transportation_price = 1400;
else if(transportation_type == 'B', 'b' && src_city == 'N', 'n' && dest_city == 'M', 'm')
transportation_price = 700;
else if(transportation_type == 'B', 'b' && src_city == 'N', 'n' && dest_city == 'K', 'k')
transportation_price = 1000;
else if(transportation_type == 'B', 'b' && src_city == 'N', 'n' && dest_city == 'C', 'c')
transportation_price = 1300;
else if(transportation_type == 'A', 'a' && src_city == 'P', 'p' && dest_city == 'D', 'd')
transportation_price = 5000;
else if(transportation_type == 'A', 'a' && src_city == 'P', 'p' && dest_city == 'M', 'm')
transportation_price = 4500;
else if(transportation_type == 'A', 'a' && src_city == 'P', 'p' && dest_city == 'K', 'k')
transportation_price = 3000;
else if(transportation_type == 'A', 'a' && src_city == 'P', 'p' && dest_city == 'C', 'c')
transportation_price = 4500;
else if(transportation_type == 'T', 't' && src_city == 'P', 'p' && dest_city == 'D', 'd')
transportation_price = 2000;
else if(transportation_type == 'T', 't' && src_city == 'P', 'p' && dest_city == 'M', 'm')
transportation_price = 1900;
else if(transportation_type == 'T', 't' && src_city == 'P', 'p' && dest_city == 'K', 'k')
transportation_price = 1200;
else if(transportation_type == 'T', 't' && src_city == 'P', 'p' && dest_city == 'C', 'c')
transportation_price = 1700;
else if(transportation_type == 'B', 'b' && src_city == 'P', 'p' && dest_city == 'D', 'd')
transportation_price = 1400;
else if(transportation_type == 'B', 'b' && src_city == 'P', 'p' && dest_city == 'M', 'm')
transportation_price = 1300;
else if(transportation_type == 'B', 'b' && src_city == 'P', 'p' && dest_city == 'K', 'k')
transportation_price = 800;
else if(transportation_type == 'B', 'b' && src_city == 'P', 'p' && dest_city == 'C', 'c');
transportation_price = 1300;
I use chars to symbolize each city and form of transportation. This if/else if statement does not work, as in my output all it gives me is a value of $1300 despite what the user enters.
Is there any way I can shorten this down? Or if I messed up somewhere can someone point it out for me?
Any help is appreciated!
Aucun commentaire:
Enregistrer un commentaire