Statements printing twice?

I wrote this program to find the target heart rate zone of people depending on their age. The program runs perfectly fine the only problem that I am having is that the statements in line 64 and 65 will print out twice, and I am absolutely puzzled as to why.

Help?

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

using namespace std;    

int main()
{

   //declare variables
   int age;                      
   double heartbeatsMinute;         

   // find age
   cout << "How old are you? " << endl;
   cin >> age;

   // validate age and run loop
   while (age > 0)
   {
      
      cout << "What is your heart rate?"<< endl;
      cin >> heartbeatsMinute;


      //validate heartrate
      bool targetRate = heartRate(age, heartbeatsMinute);

      
      heartRate(age, heartbeatsMinute);

      // cout info when true
      if (targetRate == true)
      {
         cout << "You are within your target heart range." << endl;
         cout << "Enter another age: ";
         cin >> age;
      }
      else
      {
         cout << "You are not within your target heart range." << endl;
         cout << "Enter another age: ";
         cin >> age;
      }

   }

   return 0;
}

// heartRate function
bool heartRate(int age, int heartbeatsMinute)
{

   //declare new set of varibles
   const double minRate = 0.60; 
   const double maxRate = 0.70;
   const int ConstBPM = 220;    
   double targetHigh, targetLow; 

   // calculations
   targetHigh = ((ConstBPM - age) * maxRate); 

   targetLow = ((ConstBPM - age) * minRate); 

   cout << "Your max target heart rate is " << targetHigh << " BPM." << endl;
   cout << "Your minimum target heart rate is " << targetLow << " BPM." << endl;

   // If greater than target rate return true
   if (heartbeatsMinute >= targetLow && heartbeatsMinute <= targetHigh)
   {
      return true;
   }
   else
   {
      return false;
   }

}
They print twice because you call the function twice, once on line 25 and once on line 28.

Topic archived. No new replies allowed.