Advertisement
Spocoman

Baking Competition

Oct 6th, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int bakers, totalSweets = 0;
  8.     cin >> bakers;
  9.     cin.ignore();
  10.     string command;
  11.     double totalSum = 0;
  12.  
  13.     for (int i = 0; i < bakers; i++) {
  14.         string baker = "";
  15.         int cookies = 0, cakes = 0, waffles = 0;
  16.  
  17.         while (true) {
  18.             getline(cin, command);
  19.             if (command == "Stop baking!") {
  20.                 break;
  21.             }
  22.  
  23.             if (baker == "") {
  24.                 baker = command;
  25.             }
  26.             else {
  27.                 string sweet = command;
  28.                 int sweetCount;
  29.                 cin >> sweetCount;
  30.                 cin.ignore();
  31.                 if (sweet == "cookies") {
  32.                     cookies += sweetCount;
  33.                 }
  34.                 else if (sweet == "cakes") {
  35.                     cakes += sweetCount;
  36.                 }
  37.                 else {
  38.                     waffles += sweetCount;
  39.                 }
  40.                 totalSweets += sweetCount;
  41.             }
  42.         }
  43.         totalSum += 1.50 * cookies + 7.80 * cakes + 2.30 * waffles;
  44.         printf("%s baked %i cookies, %i cakes and %i waffles.\n", baker.c_str(), cookies, cakes, waffles);
  45.     }
  46.  
  47.     printf("All bakery sold: %i\nTotal sum for charity: %.2f lv.\n", totalSweets, totalSum);
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement