I need to use printf and scanf I need the header files to use ONLY #include \"st
ID: 3679220 • Letter: I
Question
I need to use printf and scanf
I need the header files to use ONLY #include "stdafx.h" #include <stdio.h> #include <math.h>
An example of the SCALE program refrenced is in the book Problem Solving and Program Design in C 8th Edition pg 142-143 Figure 3.23 - 3.24
Open Visual Studio on your PC and select to create a New Project, name the new project BMI , and set the Location tosave to your flashdrive to your folder called MyProgramProjects .
Using the Scale program as a guide, write a new program that contains a function called CalculateBMI to compute the Body Mass Index for a person by completing the following steps:
Write code to ask the user to enter his heightInInches and his weightInPounds. Save these values as doubles.
Write code to call a function CalculateBMI and send it these 2 double values. Store the result that will be returned by this function to a double called BodyMassIndex.
Now write the function CalculateBMI that takes in these 2 double values. It should convert the person's height to meters (heightInMeters = heightInInches/39.37). Next it should convert the person's weight to kilograms (weightInKilograms = weightInPounds/2.2). Now it should calculate the person's BMI with the following formula: BMI = weightInKilograms / pow(heightInMeters,2). Finally, it should return this result back to the main program.
The main program should print a message to the screen "The Body Mass Index for this person is: " along with with the result.
Don't forget to add a line at the very top: #include "stdafx.h" (needed for VisualStudio software). Save your program and Build it.
Explanation / Answer
Program is given below:
Here we are calculating body mass index from a function and returing the bmi value main function. And from main function we are printing the value of BMI
#include "stdafx.h"
#include<stdio.h>
#include<math.h>
double CalculateBMI(double, double); //function to calculate body mass index
int main(void)
{
double heightInInches, weightInPounds, BodyMassIndex;
printf("Enter the height in inches ");
scanf("%lf", &heightInInches);
printf("Enter the weight in pounds ");
scanf("%lf", &weightInPounds);
BodyMassIndex = CalculateBMI(heightInInches, weightInPounds );
printf("The Body Mass Index for this person is %lf", BodyMassIndex );
}
double CalculateBMI(double height, double weight)
{
double heightInMeters = height/39.37;
double weightInKilograms = weight/2.2;
double tempHeightValue = pow(heightInMeters, 2);
double bmi = weightInKilograms/tempHeightValue;
return bmi;
}