-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule4LabWeek2-BMICalc.cpp
More file actions
81 lines (63 loc) · 2.05 KB
/
Copy pathModule4LabWeek2-BMICalc.cpp
File metadata and controls
81 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//************************************************************************
// Author: Rolando Carreon
// Date: mar 27 2025
// Language: C++
// Assignment: Module 4 Lab Week 2 BMI Calculator
// Description: Program that calculates the Body Mass Index (BMI) using
// user-defined functions.
//************************************************************************
#include<iostream>
using namespace std;
// function prototypes
void getWeightHeight(double&, double&);
double calcBMI(double, double);
string classifyBMI(double);
int main()
{
// declare local variables
double weight; // parameter
double height; // parameter
double BMI; // returned from calcBMI
string category; // returned from classifyBMI
// prompt user and obtain user weight and height
getWeightHeight(weight, height);
cout << "BMI Classification" << endl;
// using user weight and height calculate BMI Score and save to main
BMI = calcBMI(weight, height);
// display BMI Score
cout << "BMI: " << BMI << endl;
// using BMI score, find and display category
cout << "Classification: " << classifyBMI(BMI) << endl << endl;
return 0;
}
// funciton definitions
// function to prompt user for weight and height, passes to main
void getWeightHeight(double& weight, double& height)
{
cout << "Enter the weight in kilograms: ";
cin >> weight;
cout << "Enter the height in meters: ";
cin >> height;
cout << endl;
}
// calculates BMI score using BMI formula and returns to main
double calcBMI(double weight, double height)
{
double BMI;
BMI = weight / (height * height);
return BMI;
}
// using calculated BMI score, return a category based on BMI rules
string classifyBMI(double BMI)
{
string category;
if (BMI < 18.5)
category = "Underweight";
else if (BMI >= 18.5 && BMI <= 25)
category = "Normal weight";
else if (BMI >= 25 && BMI <= 30)
category = "Overweight";
else
category = "Obese";
return category;
}