The maximum weight y (in pounds) for a man in the United States Marine Corps can be approximated by the mathematical model
y=0.040x2 −0.11x+3.9, 58≤x≤80
where x is the man’s height (in inches).
Design an algorithm and write a C++ program that prompts the user to input the height in inches. The program calculates and outputs the weight in pounds.
Algorithm
Start
Declare real heigh
Declare real weight
while height<58 or height>80
Display "Input the height in inches [58-80]: "
intput height
End while
Set weight=0.040*height*height-0.11*height+3.9
Display "The weight: ",weight," pounds"
Stop
C++ program
#include <iostream>
#include <string>
using namespace std;
int main(void){
float height=0;
while(height<58 || height>80){
cout<<"Input the height in inches [58-80]: ";
cin>>height;
}
float weight=0.040*height*height-0.11*height+3.9;
cout<<"The weight: "<<weight<<" pounds\n\n";
system("pause");
return 0;
}
Comments
Leave a comment