Answer to Question #124430 in C++ for Agyei Ebenezer

Question #124430
5. Write a program that displays the recommended weight in kilograms, given the user’s age and height in centimeters. The formula for calculating the recommended weight is
Recommended = (height – 100 + age %10) *0.90
1
Expert's answer
2020-06-30T07:59:37-0400

// the preprocessing directives

#include <iostream>

#include <iomanip>   // setprecision(2) and fixed

 

using namespace std;

 

int main() {

           // declare and initialize variables    

  int height;

  float age, weight;

  cout << setprecision(2) << fixed;

  

           cout << "Age: ";

           cin >> age;

 

           cout << "Height (cm): ";

           cin >> height;

           

           if(age>0 && height>0 ){

                       weight = float(height-100 + int(age)%10)*0.90 ;

                       cout<<"Recommended weight: "<< weight<<endl;

           }

           else

                       cout << endl <<"Age and Height must be positive numbers "<<endl;

   return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS