60 472
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #46617 in C++ for amanda shaffer

Question #46617
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.
Expert's answer
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions