Scientists measure an object 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. Weight = mass * 9.8 write a program that asks the user to enter an object mass and then calculate the weight of an object. If its weight is more than 1000 newtons then display the message that it’s too heavy. If its weight is less than 10 newtons then display message that it’s too light. Solve the task using the conditional Operators.
code:
#include <iostream>
using namespace std;
int main()
{
double mass;
cout << "Enter the value of mass";
cin >> mass;
string result;
double mass1 = mass*9.8;
result = (mass1 > 1000) ? "Too Heavy" : ((mass < 10) ? "too light" : "in middle between too heavy and too light");
cout << result;
return 0;
}
output :
Enter the value of mass 100
100
in middle between too heavy and too light
0 Comments