Return type with void but no argument

Write a class called “client”.

Your client class will have the following private data members:

• A string for the client’s first name
• A string for the client’s last name
• A float for the client’s height in inches
• An int for the client’s weight in pounds
• A float for the client’s body mass index (BMI)
• An int for the client’s calorie requirements
• A char for the client’s gender

Your client class will have the following public member functions:

 A constructor that accepts 5 arguments. The 5 arguments represent the client’s 1) first name (string), 2) last name (string), 3) height (float), 4) weight (int), and 5) gender (char). The values for these parameters will be passed from main upon the creation of the client object, and your constructor will use those values to initialize the appropriate private data members.

 A member function that will calculate the BMI. This function will accept no arguments and will have a return type of void. The function will calculate the BMI using the formula on the next page and based on the height and weight private data members.

Body mass index (BMI) formula:
BMI = (weight / (height * height))*703

Where weight is the client’s weight in pounds, and height is the client’s height in inches.

 A function that will calculate a client’s calorie requirements. This function will accept no arguments and will have a return type of void. Calorie requirements are the number of calories a client needs to ingest daily in order to maintain his/her current weight. Your function will calculate the calorie requirements based on the weight and gender data members and using the criteria below.

Criteria for Calorie Requirements (assuming moderate activity level for all clients)
--For a female: 18 calories per pound of body weight
--For a male: 21 calories per pound of body weight

 A function to print the client’s information. This function will accept no arguments and will have a return type of void. It will print the client’s full name, gender, height, weight, BMI, and calorie requirements. Additionally, this function will print a statement about the client’s BMI based on the table below (e.g. “Your BMI falls within the optimal range”). If a client’s BMI is below or exceeding optimal range, advise him/her to make an appointment with the nutritionist.

In main, first ask the user for the client’s 1) first name, 2) last name, 3) gender, 4) height in inches, and 5) weight in pounds. After you have obtained these values, create a client object and pass the values as arguments, thus executing the 5 argument constructor. Once the object has been created, you can invoke the member functions to calculate the BMI, calculate the calorie requirements, and lastly, print the client’s information.

I'm having trouble figuring out how to return my bmi and calorie calculation back into my main function with no arguments.
I've tried using
"return bmi;"
"{return bmi;}" Next to the function also

If there is any other problem with my program please let me know, much appreciated.

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;



class client
{

private:
	string FirstName;
	string LastName;
	float height;
	int weight;
	float bmi;
	int calories;
	char gender;

public:
	client(){}

	client(string f, string l, float h, int w, char g)
	{
		FirstName = f;
		LastName = l;
		height = h;
		weight = w;
		gender = g;

	}
	void ClientInfo(string f, string l, float h, int w, char g)
	{
		FirstName = f;
		LastName = l;
		height = h;
		weight = w;
		gender = g;

	}

	void BMI()
	{
		bmi = (weight / (height * height)) * 703;
	}

	void Calorie()
	{
		
		if (gender == 'm' || gender == 'M')
		{
			calories = (weight * 21);
		}
		else if (gender == 'f' || gender == 'F')
		{
			calories = (weight * 18);
			
		}
		return;
	}
	void Information()
	{
		if (bmi <= 18.5)
		{
			cout << FirstName << LastName << " your BMI is " << bmi << endl;
			cout << "Your BMI fall below Optimal Range " << endl;
			cout << "Please schedule an appiontment with nutritionist" << endl;
		}
		else if (bmi >= 18.5 && bmi <= 24.9)
		{
			cout << FirstName << LastName << " your BMI is " << bmi << endl;
			cout << "Your BMI is Optimal Range" << endl;
		}
		else (bmi >= 25);
		{
			cout << FirstName << LastName << " your BMI is " << bmi << endl;
			cout << "Your BMI exceeds Optimal Range" << endl;
			cout << "Please schedule an appiontment with nutritionist" << endl;
		}
	}
};
int main()
{
	client Info[5];
	string FirstName;
	string LastName;
	float height;
	int weight;
	float bmi = 0;
	int calories = 0;
	char gender;

	client c1("", "", 0, 0, 'g');
	c1.BMI();
	

	cout << "Enter client's First Name: ";
	cin >> FirstName;
	cout << "Enter client's Last Name: ";
	cin >> LastName;
	cout << "Enter client's Gender (m/f): ";
	cin >> gender;
	cout << "Enter " << FirstName << "'s height in inches: ";
	cin >> height;
	cout << "Enter " << FirstName << "'s weight in pounds: ";
	cin >> weight;

	cout << endl << endl << "Client's Name: " << FirstName << " " << LastName << endl;
	cout << "Gender: " << gender << endl;
	cout << "Height in inches: " << height << endl;
	cout << "Weight in pounds: " << weight << endl;
	cout << "Calorie Requirmemnt: " << calories << endl;
	cout << "Body Mass Index: " << bmi << endl;

	c1.Calorie();
	c1.Information();

	system("PAUSE");
	return 0;
}
Last edited on
closed account (E0p9LyTq)
In your class definition:
1
2
3
4
5
float BMI()
{
   bmi = (weight / (height * height)) * 703;
   return bmi;
}

and in main():
bmi = c1.BMI();

returning a BMI value won't matter. height and weight are being set at zero when you create your client object and are not updated.
I see what you mean, I should of put the instructions of what I need to do because I'm not sure if I can actually make the function into a Float but it into a void. Unless I'm wrong which then its understandable. I updated the post.
Can you make a getBMI() function which simply returns the BMI?
closed account (E0p9LyTq)
There is no method to actually get the BMI value out of your client object, based on what you've posted of the requirements. Either have a non-void return, or create a separate GetBMI() method.

Same for the Caloric requirement. You can calculate the value, but no means to get the data.

Based on the posted requirements you are creating your client object too early as well, you create it AFTER getting the use input.
Yes! It worked, you were right about doing it to early and I get the correct number now by changing the client object. Thank you for helping!

But still have the problem with getting the bmi and calories to calculate and output it.
Last edited on
Line 22: Your default constructor leaves your member variables uninitialized.

Lines 64-80: Your if statements have a number of problems.
line 70: The condition (bmi >= 18.5i) is unnecessary. If it's not <= 18.5 and you execute the else, the bmi can only be > 18.5.

Lines 64,70: You don't want to test both <= and >=. If the bmi is exactly 18.5, only the first set of statements will be executed.

Line 75: You can't put a condition on an else clause.
The ; terminates the else clause. Lines 76-80 will be executed unconditionally.

But still have the problem with getting the bmi and calories to calculate and output it.

IMO, you should be calculating bmi and calories whenever you set the patient information. That way, the values for bmi and calories are always correct.

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
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class client
{   string FirstName;
	string LastName;
	float height;
	int weight;
	float bmi;
	int calories;
	char gender;

public:
	client()
	{   height = 0;
	    weight = 0;
	    bmi = 0;
	    calories = 0;
	    gender = ' ';
	}

	client(string f, string l, float h, int w, char g)
	{   FirstName = f;
		LastName = l;
		height = h;
		weight = w;
		gender = g;
        calculateBMI ();        //  Set bmi
        calculateCalories();    //  Set calories
	}
	//  ClientInfo not needed.  Use value constructor

	void calculateBMI()
	{   bmi = (weight / (height * height)) * 703;
	}

	void calculateCalories()
	{   if (gender == 'm' || gender == 'M')
		{   calories = (weight * 21);
		}
		else if (gender == 'f' || gender == 'F')
		{   calories = (weight * 18);
		}
	}
	
	void Information()
	{   cout << endl << endl << "Client's Name: " << FirstName << " " << LastName << endl;
	    cout << "Gender: " << gender << endl;
	    cout << "Height in inches: " << height << endl;
	    cout << "Weight in pounds: " << weight << endl;
	    cout << "Calorie Requirmemnt: " << calories << endl;
	    cout << "Body Mass Index: " << bmi << endl;
	    if (bmi <= 18.5)
		{   cout << "Your BMI fall below Optimal Range " << endl;
			cout << "Please schedule an appiontment with nutritionist" << endl;
		}
		else if (bmi <= 24.9)
		{   cout << "Your BMI is Optimal Range" << endl;
		}
		else 
		{   cout << "Your BMI exceeds Optimal Range" << endl;
			cout << "Please schedule an appiontment with nutritionist" << endl;
		}
	}
};

int main()
{   string FirstName;
	string LastName;
	float height;
	int weight;
	char gender;

	cout << "Enter client's First Name: ";
	cin >> FirstName;
	cout << "Enter client's Last Name: ";
	cin >> LastName;
	cout << "Enter client's Gender (m/f): ";
	cin >> gender;
	cout << "Enter " << FirstName << "'s height in inches: ";
	cin >> height;
	cout << "Enter " << FirstName << "'s weight in pounds: ";
	cin >> weight;

    client c1 (FirstName, LastName, height, weight, gender);
	c1.Information();

	system("PAUSE");
	return 0;
}
Last edited on
closed account (E0p9LyTq)
IMO, you should be calculating bmi and calories whenever you set the patient information.


That is not fulfilling the requirements. The class is required to have two methods to calculate the BMI and caloric amount separately from the output.

Ask for client's information.
Create the client object based on given information.
Calculate the BMI.
Calculate the Calories.
Output the client's chart.

@FurryGuy
That is not fulfilling the requirements

I did not eliminate the two functions. I simply made a statement as to where they should be called.

If you check the code I posted, lines 30 and 31 call the two required functions from the constructor where the height and weight are set.



Last edited on
Topic archived. No new replies allowed.