modulus.cpp 489 B

123456789101112131415161718
  1. // modulus.cpp -- uses % operator to convert lbs to stone
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. const int Lbs_per_stn = 14;
  7. int lbs;
  8. cout << "Enter your weight in pounds: ";
  9. cin >> lbs;
  10. int stone = lbs / Lbs_per_stn; // whole stone
  11. int pounds = lbs % Lbs_per_stn; // remainder in pounds
  12. cout << lbs << " pounds are " << stone
  13. << " stone, " << pounds << " pound(s).\n";
  14. // cin.get();
  15. // cin.get();
  16. return 0;
  17. }