#include <stdio.h>
int main(void) {
// ask user to enter number of plates and price of one plate
int platesNum;
float platePrice;
printf("Enter number of plates: ");
scanf("%i", &platesNum);
printf("Enter price of one plate: ");
scanf("%f", &platePrice);
// ask user to enter number of cups and price of one cup
int cupsNum;
float cupPrice;
printf("Enter number of cups: ");
scanf("%i", &cupsNum);
printf("Enter price of one cup: ");
scanf("%f", &cupPrice);
// ask user to enter amount to pay
float amount;
printf("Enter amount to pay: ");
scanf("%f", &amount);
// display change
float sum = (platesNum * platePrice) + (cupsNum * cupPrice);
if (sum > amount) {
printf("Not enough amount to pay!");
} else {
printf("Your change is: %.2f", amount - sum);
}
return 0;
}
Comments
Leave a comment