Functions and a mistake

I need to pass variables from one function to another and neither function is the main function and the variables are not global. Thing is I have no idea how to do that and am new to programming. Also I have never used this website so I apologize for putting the entire program in the code box.

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
#include <iostream>
#include <iomanip>

using namespace std;

int calculateMaximumHeartRate(int age)
{
	int maximumHeartRate;
	return maximumHeartRate = 220 - age;
}

// Your displayTargetHeartRate function goes here
void displayTargetHeartRate(int MaximumHeartRate)
{
	int maximumHeartRate = calculateMaximumHeartRate(age);
	double minimumTargetRate = maximumHeartRate * .6;
	double maximumTargetRate = maximumHeartRate * .7;
	cout << "Minimum target heart rate is " << minimumTargetRate << endl;
	cout << "Maximum target heart rate is " << maximumTargetRate << endl;
}

// Your processTargetHeartRate function goes here
int processTargetHeartRate()
{
	cout << "Enter your age: ";
	cin >> age;
	cout << endl;
	cout << "Enter your heart beats per minute: ";
	cin >> bpm;
	cout << endl;

	age = calculateMaximumHeartRate(age);
}

int main()
{
	processTargetHeartRate();
	processTargetHeartRate();
	processTargetHeartRate();
	return 0;
}


I need to pass the age variable from the process function to the calculate function. I also need to pass the calculate value (the final return value) to the display function to calculate the minimum and maximum heart rates. Sorry but I honestly have no idea how to do these last few steps and I could do the rest of the program with minimal difficulties. So could someone please help me?
Last edited on
not entirely sure what I did but I changed the code a little and it works now.....except that it gives me the wrong numbers.

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
#include <iostream>
#include <iomanip>

using namespace std;

// global variables
int age, bpm; // bpm is short for beats per minute

// Your processTargetHeartRate function goes here
int processTargetHeartRate()
{
	int age, bpm;
	cout << "Enter your age: ";
	cin >> age;
	cout << "Enter your heart beats per minute: ";
	cin >> bpm;

	return age, bpm;
}

int calculateMaximumHeartRate(int age)
{
	int maximumHeartRate;
	return maximumHeartRate = 220 - age;
}

// Your displayTargetHeartRate function goes here
void displayTargetHeartRate(int MaximumHeartRate, int age)
{
	int maximumHeartRate = calculateMaximumHeartRate(age);
	double minimumTargetRate = maximumHeartRate * .6;
	double maximumTargetRate = maximumHeartRate * .7;
	cout << "Minimum target heart rate is " << minimumTargetRate << endl;
	cout << "Maximum target heart rate is " << maximumTargetRate << endl;
}


int main()
{
	processTargetHeartRate();
	int maximumHeartRate = calculateMaximumHeartRate(age);
	displayTargetHeartRate(maximumHeartRate, age);
	return 0;
}


No matter what numbers I input I always get 132 and 154. What did I do wrong? if you want some examples the numbers I should be getting are as follows:
Enter your age: 21 [Enter]
Enter your heart beats per minute: 120 [Enter]
Minimum target heart rate is 119.4
Maximum target heart rate is 139.3
Enter your age: 25 [Enter]
Enter your heart beats per minute: 120 [Enter]
Minimum target heart rate is 117.0
Maximum target heart rate is 136.5
Enter your age: 33 [Enter]
Enter your heart beats per minute: 110 [Enter]
Minimum target heart rate is 112.2
Topic archived. No new replies allowed.