Advertisement
Spocoman

Care of Puppy

Sep 15th, 2023
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int foodInKilograms;
  8.     cin >> foodInKilograms;
  9.  
  10.     int availableFoodInGrams = foodInKilograms * 1000;
  11.  
  12.     string command;
  13.     cin >> command;
  14.  
  15.     while (command != "Adopted") {
  16.         availableFoodInGrams -= stoi(command);
  17.         cin >> command;
  18.     }
  19.  
  20.     if (availableFoodInGrams >= 0) {
  21.         printf("Food is enough! Leftovers: %i grams.", availableFoodInGrams);
  22.     }
  23.     else {
  24.         printf("Food is not enough. You need %i grams more.", abs(availableFoodInGrams));
  25.     }
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement