Help With boolean functions & return values

This is the prompt:
"Your Target Heart Rate is the rate at which your heart should beat to get the maximum benefit from aerobic exercise. This rate is generally agreed to be 60 to 70 percent of your maximal heart rate. Your maximal heart rate equals 220 minus your age. Create a program which includes the following: A main function that asks the user to enter an age and the number of heartbeats counted in one minute. These values should be passed to a function that will calculate the Target Heart Rate. The function should return true if the user is within his/her Target Heart Rate range and false if not. The main function or driver should then display a message indicating if the user is in his/her Target Heart Rate range. Keep prompting and reading in new ages and heart rates until the user enters a negative value for the age."

Can someone who is experience explain to me what I did wrong. Is it returning the right values?
This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

bool heart_rate(int age, int heartBeatRate)
{
   double targetRate;            // target heart beat rate
   double maxRate = 220 - age;   // calculating max heart rate
   
   // determining if the user is within the target heart beat rate
   if (targetRate >= maxRate*(.60) && targetRate <= maxRate*(.70))
   {
      return true;
   }
   else
   {
      return false;
   }
}  // end of target_heart_rate 
Last edited on
In heart_rate, targetRate is never assigned a value, so it contains whatever random junk happened to be in the memory it occupies.
target_rate isn't initialised in heart_rate().
Oh wow, how did I miss that. Thank you cire & kbw.
Topic archived. No new replies allowed.