Bluebird Airlines has flights from Phoenix to six other cities in Arizona. The cities are referred to by number, 1 to 6. The price of round trip ticket to each of the cities is shown here:
City 1 2 3 4 5 6
Price 56.79 105.69 93.49 155.99 87.49 73.99
Write a program that computes the total price of tickets that a customer orders. The program should prompt the user for the number of the destination city and the number of tickets desired. If the user enters an invalid a city number, the program should display an error message and terminate. The program should display the total price of the ticket order. Use an array to store the ticket price table.
1
Expert's answer
2014-09-24T12:28:38-0400
#include <stdio.h> #include <stdlib.h> int main() { double price[] ={56.79, 105.69, 93.49, 155.99, 87.49, 73.99}; //array init int c,n; printf("Enter the number of the city: "); scanf("%d",&c); if ( (c > 6) || (c < 1)) // check for error { printf("Error! The number of city is invalid!\n"); exit(1); } printf("Enter the number of tickets desired: "); scanf("%d",&n); double total = price[c-1] * n; // total price printf("\nTotal price number: %4.2f\n", total); system("pause"); return 0; }
Comments
Leave a comment