#include <ctime>
#include <iostream>
#include "HeartRates.h"
int main()
{
// Get current date
time_t t = time(0);
struct tm * now = localtime(&t);
int currentYear = now->tm_year + 1900;
int currentMonth = now->tm_mon + 1;
int currentMday = now->tm_mday;
HeartRates subject01;
std::cout << "Enter the name of the subject." << std::endl
<< "First name: ";
subject01.setFirstName();
std::cout << "Last name: ";
subject01.setLastName();
std::cout << std::endl << "Enter the numeric date of birth."
<< std::endl << "Month: ";
subject01.setBirthMonth();
std::cout << "Day: ";
subject01.setBirthMday();
std::cout << "Year: ";
subject01.setBirthYear();
std::cout << subject01.getFirstName() << " "
<< subject01.getLastName() << " was born "
<< subject01.getBirthMonth() << "/"
<< subject01.getBirthMday() << "/"
<< subject01.getBirthYear() << " and is "
<< subject01.ageCalculation(currentMonth, currentMday, currentYear) << " years old."
<< std::endl
<< "Maximum heart rate: " << subject01.getMaxHeart() << std::endl
<< "Target heart rate is between " << subject01.getMinTargetHeart()
<< " and " << subject01.getMaxTargetHeart() << std::endl;
}
Output:
1 2 3 4 5 6 7 8 9 10 11 12
Enter the name of the subject.
First name: John
Last name: Smith
Enter the numeric date of birth.
Month: 8
Day: 20
Year: 1980
age = -858993460.
John Smith was born 8/20/1980 and is 36 years old.
Maximum heart rate: 858993680
Target heart rate is between -429496730 and -730144441
Everything works fine until after I enter in the year of birth.
you're placing functions inside of functions inside of functions when you do a long chain with the cout and << operators
when you say
"Maximum heart rate: " << subject01.getMaxHeart() << std::endl
subject01.getMaxheart() has to get evaluated first so you're gonna get an out put for age before it's actually calculated and then anything with age is gonna be messed up
as a rule of thumb you want "get" functions to only return values and nothing else.
they shouldn't change or set anything.