avr39ripe

sumToGrnKop

Dec 24th, 2020 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int kopInGrn{ 100 };
  6.     double sum{64.70};
  7.     int grn;
  8.     int kop;
  9.  
  10.     std::cout << "Enter the summ: ";
  11.     std::cin >> sum;
  12.  
  13.     // Variant A - simpler to understand how it works
  14.     //kop = sum * kopInGrn;
  15.     //grn = kop / kopInGrn;
  16.     //kop %= kopInGrn;
  17.  
  18.     // Variant B - shorter :)
  19.     grn = sum;
  20.     kop = (sum - grn) * kopInGrn;
  21.  
  22.     std::cout << "The summ is equal: " << grn << " grn. " << kop << " kop.\n";
  23.  
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment