fork download
  1. // Haroon Achackzad CS1A Chapter 4, P. 220, #6
  2. //
  3. /**************************************************************
  4.  *
  5.  * Mass and Weight
  6.  * ____________________________________________________________
  7.  * This program asks a user to enter a mass in between 10-1000 Newtons
  8.  * and to calculate the weight of that object through user input within
  9.  * range.
  10.  *
  11.  * Computation is based on the formula:
  12.  * Weight= Mass* 9.8
  13.  * ____________________________________________________________
  14.  * INPUT
  15.  * mass= Force of Gravity on an object
  16.  *
  17.  * OUTPUT
  18.  * weight: product of mass *9.8
  19.  *
  20.  **************************************************************/
  21.  
  22. #include <iostream>
  23. using namespace std;
  24.  
  25. int main() {
  26.  
  27. //variables
  28.  
  29. float weight,
  30. mass;
  31.  
  32. // Make user enter the Object's mass
  33.  
  34. cout << endl;
  35. cout << "What is the object's mass: ";
  36. cin >> mass;
  37.  
  38. // Calculation for Weight
  39.  
  40. weight = mass * 9.8;
  41.  
  42. //Show weight on display
  43.  
  44. cout << "\nObject's weight = ";
  45. cout << weight << endl << endl;
  46.  
  47. if (weight >= 1000)
  48. cout << "too heavy. ";
  49. else if (weight <= 10)
  50. cout << "too light. ";
  51. else
  52. cout << "Neither Heavy or too light. ";
  53.  
  54. cout << endl << endl;
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5472KB
stdin
Standard input is empty
stdout
What is the object's mass: 
Object's weight = 4.49981e-40

too light.