Answer:
Follows are the code to this question:
#include <stdio.h>//header file
#include <string.h>//header file
int main()//main method
{
char f_service[100], s_service[100];//defining character array
int total;//defining integer variable
do
{
total = 0;//assign value in total variable
printf("Davy's auto shop services\n");//print message
printf("Oil change -------- $35\n");//print message
printf("Tire rotation ------ $19\n");//print message
printf("Car wash ---------- $7\n");//print message
printf("Car wax ----------- $12\n");//print message
printf("Enter first service: \n");//print message
fgets(f_service, 100, stdin);//use get function for input value
f_service[strlen(f_service) - 1] = '\0';//use length function for calculate total length
printf("Enter second service: \n");//print message
fgets(s_service, 100, stdin);//use get function for input value
s_service[strlen(s_service) - 1] = '\0';//use length function for calculate total length
printf("\nDavy's auto shop invoice\n\n");//print message
if(strcmp(f_service, "Oil change") == 0)//defining if block that check first input Service
{
printf("Service 1: %s, $%d\n", f_service, 35);//print service name with rate
total = total+ 35;//calcaulte value in total variable
}
else if(strcmp(f_service, "Tire rotation")== 0)
{
printf("Service 1: %s, $%d\n", f_service,19); //print service name with rate
total = total + 19;//calcaulte value in total variable
}
else if(strcmp(f_service, "Car wash") == 0)
{
printf("Service 1: %s, $%d\n", f_service, 7);//print service name with rate
total = total + 7;//calcaulte value in total variable
}
else if(strcmp(f_service, "Car wax") == 0)
{
printf("Service 1: %s, $%d\n", f_service, 12); //print service name with rate
total = total + 12;//calcaulte value in total variable
}
else
{
printf("Service 1: Empty\n");//print message
}
if(strcmp(s_service, "Oil change") == 0)
{
printf("Service 2: %s, $%d\n", s_service, 35);//print service name with rate
total= total+ 35;//calcaulte value in total variable
}
else if(strcmp(s_service, "Tire rotation")== 0)
{
printf("Service 2: %s, $%d\n", s_service, 19);//print service name with rate
total = total + 19;//calcaulte value in total variable
}
else if(strcmp(s_service, "Car wash") == 0)
{
printf("Service 2: %s, $%d\n", s_service, 7);//print service name with rate
total = total + 7;//calcaulte value in total variable
}
else if(strcmp(s_service, "Car wax") == 0)
{
printf("Service 2: %s, $%d\n", s_service, 12);//print service name with rate
total= total+ 12;//calcaulte value in total variable
}
else if(strcmp(s_service, " ") == 0)
{
printf("Service 2: No service\n");//print service name with rate
}
else
{
printf("Service 2:No service\n");//print message
}
printf("Total: $%d\n", total);//print total value
}
while(strcmp(s_service, "_"));//defining while that compare second service value
return 0;
}
Output:
Please find the attached file.
Explanation:
In the given C language code, the two-character array "f_service and s_service" and one integer variable "total" is declared, in which character array is used for user input, and the total is used for calculating value.
- In the next step, the do-while loop is used, in which we used multiple conditional statements, that check "first and second" both array input value and add values into the total variable.
- If the first array doesn't take any input value, it will print an "empty" message. Similarly, in the second array, if it can't take any value, it will print a message "No service", and for the exit from the program, we pass the "underscore (_)" symbol.