140k views
4 votes
Prompt the user for an automobile service. Each service type is composed of two strings. Output the user's input. (1 pt) Ex: Enter desired auto service: Oil change You entered: Oil change (2) Output the price of the requested service. (4 pts) Ex: Enter desired auto service: Oil change You entered: Oil change Cost of oil change: $35 The program should support the following services: Oil change -- $35 Tire rotation -- $19 Car wash -- $7 If the user enters a service that is not listed above, then output the following error message: Error: Requested service is not recognized

2 Answers

3 votes

Final answer:

To prompt the user for an automobile service and output their input, use the input() and print() functions in Python. To output the price of the requested service, use an if-elif-else statement to check the input and print the corresponding price. Display an error message if the service is not recognized.

Step-by-step explanation:

To prompt the user for an automobile service, you can use the input() function in Python. You can then store the user's input in a variable and output it using the print() function. For example:

service = input('Enter desired auto service: ') print('You entered:', service)

To output the price of the requested service, you can use an if-elif-else statement to check the user's input and print the corresponding price. For example:

if service == 'Oil change': print('Cost of oil change: $35') elif service == 'Tire rotation': print('Cost of tire rotation: $19') elif service == 'Car wash': print('Cost of car wash: $7') else: print('Error: Requested service is not recognized')

This code will output the price of the requested service based on the user's input. If the user enters a service that is not listed, the program will display an error message.

User Duncan Benoit
by
4.6k points
3 votes

Answer:

Required code is given below.

Best Regards,

Please ask if any queries.

Step-by-step explanation:

#include <stdio.h>

#include <string.h>

int main(void)

{

char input[100];

printf("Enter desired auto service:\\");

scanf ("%[^\\]%*c", input);

printf("You entered: %s\\",input);

if(strcmp(input,"Oil change") == 0){

printf("Cost of oil change: $35\\");

}

else if(strcmp(input,"Tire rotation") == 0){

printf("Cost of tire rotation: $19\\");

}

else if(strcmp(input,"Car wash") == 0){

printf("Cost of car wash: $7\\");

}

else{

printf("Error: Requested service is not recognized\\");

}

return 0;

}