Programming Challenge Chapter 4 – Q #6 Mass and Weight – Tony Gaddis – Starting Out With C++
Problem: -
Scientists measure an object s mass in kilograms and its weight in newtons. If you
know the amount of mass that an object has, you can calculate its weight, in newtons,
with the following formula:
Weight = mass × 9.8
Write a program that asks the user to enter an object s mass, and then calculates and
displays its weight. If the object weighs more than 1,000 newtons, display a message
indicating that it is too heavy. If the object weighs less than 10 newtons, display a
message indicating that the object is too light.
Solution: -
#include<iostream>
using namespace std;
int main()
{
//Declare Variables
float mass, weight;
//Take Input From The User
cout << "Enter Mass in Kilograms: ";
cin >> mass;
//Calculate Weight By Using Given Formula
weight = mass * 9.8;
//Use if else if condition for checking
if (weight > 1000)
cout << "The object is too heavy";
else if (weight < 10)
cout << "The object is too light";
else
cout << "The object is optimal";
//Return 0 To the main Function
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Explanation of this Solution
Solution Explain With Comments in Solution.
Also, I attach CPP file of this problem. You can download this file
0 Comments