rite a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total. Sample Run Enter the subtotal and a gratuity rate: 10 15 The gratuity is $1.5 and total is $11.5
Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total.
For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.
Sample Run
Enter the subtotal and a gratuity rate: 10 15
The gratuity is $1.5 and total is $11.5
Approach:-
first read subtotal and GratuityRate
Calculating Gratuity :-
Gratuity = (subtotal * GratuityRate ) / 100 .
Calculating Total :-
total =subtotal + Gratuity
Code in C Language :-
#include <stdio.h> // c language header file for standard input and output
int main() // main function
{
float subtotal,gratuity_rate; // variable declaration
float gratuity,total; // variable declrationg
printf("Enter the subtotal and a gratuity rate: ");
scanf("%f%f",&subtotal,&gratuity_rate); // taking input
gratuity=gratuity_rate*subtotal/100.0; // calculating gratuity
total=gratuity+subtotal; // calculating total
printf("The gratuity is $%0.1f and total is $%0.1f",gratuity,total);
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images