Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define CHAIR_PRICE 13.99
- #define TABLE_PRICE 42.00
- #define GLASS_PRICE 5.98
- #define CUTLERY_PRICE 21.02
- int main() {
- int numGuests;
- char item[10];
- double totalCost = 0.0;
- double price_table_for_one = TABLE_PRICE / 8;
- double one_pair_glass = GLASS_PRICE / 6;
- double one_pair_cutlery = CUTLERY_PRICE / 6;
- printf("Enter the number of guests: ");
- scanf("%d", &numGuests);
- while (1) {
- printf("Enter an item (or 'PARTY!' to stop): ");
- scanf("%s", item);
- if (strcmp(item, "PARTY!") == 0) {
- break;
- }
- if (item == "chair") {
- totalCost += CHAIR_PRICE * numGuests;
- } else if (item == "table") {
- totalCost += price_table_for_one * numGuests;
- } else if (item == "glass") {
- totalCost += one_pair_glass * numGuests;
- } else if (item == "cutlery") {
- totalCost += one_pair_cutlery * numGuests;
- }
- }
- // Add the cost for each guest
- // totalCost += (numGuests * GLASS_PRICE) + ((numGuests / 8) * CUTLERY_PRICE);
- printf("Total cost for organizing the party: $%.2lf\n", totalCost);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment