fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH4 HW Q:1
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Weight Calculator
  6.  *
  7.  *********************
  8.  *
  9.  * The program asks the user to enter an object's mass, and then calculates
  10.  * and shows its weight. If the object is more than 1,000 newtons,
  11.  * it will display a message saying that it is too heavy. If the object weighs
  12.  * less than 10 newtons, it will display a message saying that it is too light.
  13.  *
  14.  * Weight = mass × 9.8
  15.  *
  16.  * INPUT
  17.  * mass : Mass of the object in kilogram
  18.  *
  19.  * OUTPUT
  20.  * weight : Weight in newtons
  21.  * message : Message if too heavy or too light
  22.  *
  23.  ****************************************************************************/
  24.  
  25. #include <iostream>
  26. #include <iomanip>
  27. using namespace std;
  28.  
  29. int main()
  30. {
  31. const double GRAVITY = 9.8;
  32. const double MAX_WEIGHT = 1000.0;
  33. const double MIN_WEIGHT = 10.0;
  34.  
  35. double mass;
  36. double weight;
  37.  
  38. cout << "Enter the object's mass in kilograms: ";
  39. cin >> mass;
  40.  
  41. weight = mass * GRAVITY;
  42.  
  43. cout << fixed << setprecision(2);
  44. cout << "Weight: " << weight << " newtons\n";
  45.  
  46. if (weight > MAX_WEIGHT)
  47. cout << "The object is too heavy.\n";
  48. else if (weight < MIN_WEIGHT)
  49. cout << "The object is too light.\n";
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter the object's mass in kilograms: Weight: 0.00 newtons
The object is too light.