printing out weird negative number(read last post)

Header File:

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
/*#include <iostream>
#include <string>
using namespace std;

class heartRates
{
	string first;
	string last;
	int month;
	int day;
	int year;
	int age;
	int curyear;
	int max;
	double hi;
	double lo;
	int c;

public:
    heartRates (string, string, int, int, int, int);
	void setFirst(string);
	void setLast(string);
	void setMonth(int);
	void setDay(int);
	void setYear(int);
	void setcuryear(int);
	string getFirst();
	string getLast();
	int getMonth();
	int getDay();
	int getYear();
	int getAge(int);
	int getcuryear();
	int getMaximumHeartRate();
	double getTargetHeartRate(int);
	void displayInfo(int, int);

};
*/







Code:
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
/#include <iostream>
#include <string>
#include "heartRates.h"
using namespace std;

string heartRates::getFirst()
{
	return first;
}

string heartRates::getLast()
{
	return last;
}

void heartRates::setFirst(string f)
{
	first = f;
}

void heartRates::setLast(string l)
{
	last = l;
}

int heartRates::getMonth()
{
	return month;
}

int heartRates::getDay()
{
	return day;
}

int heartRates::getYear()
{
	return year;
}

int heartRates::getcuryear()
{
	return c;
}

void heartRates::setDay(int d)
{
	day = d;
}

void heartRates::setMonth(int m)
{
	month = m;
}

void heartRates::setYear(int y)
{
	year = y;
}

void heartRates::setcuryear(int c)
{
	curyear = c;
}

int heartRates::getAge(int y)
{
	age = c - y;
	return age;
}

int heartRates::getMaximumHeartRate()
{
	max = 220 - age;
	return max;
}

double heartRates::getTargetHeartRate(int max)
{
	hi = .85 * max;
	lo = .5 * max;
	return hi;
	return lo;
}

heartRates::heartRates (string f, string l, int m, int d, int y, int c)
{
	heartRates::setcuryear(c);
	heartRates::setDay(d);
	heartRates::setMonth(m);
	heartRates::setYear(y);
	heartRates::setFirst(f);
	heartRates::setLast(l);
}

void heartRates::displayInfo(int hi, int lo, int y)
{
	cout << "Your information is as follows:" << endl;
	cout << getLast() << ", " << getFirst() << endl;
	cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
	cout << "Current age is: " << getAge(y) << endl;
	cout << "Maximum heart rate is: " << getMaximumHeartRate() << endl;
	cout << "Target heart range is between: " << hi << " and " << lo << endl;
}






/




Test code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/#include <iostream>
#include <string>
using namespace std;
#include "heartRates.h"

int main()
{
	heartRates rate("Jennifer", "Morris", 8, 4, 1988, 2010);

	rate.displayInfo();


	return 0;
}/


Above are my header file, code, and test code. The purpose is to, given the first name, last name, and DOB, calculate the maximum heart rate and target heart rate of an individual. I am getting an error that say "displayInfo does not take zero arguments but every time i try to put in an argument for the parameter I get "undeclared identifier" errors.
Last edited on
What are putting in as the arguments? It wants three ints.
void heartRates::displayInfo(int hi, int lo, int y)

here you declare the "displayInfo" function which accepts three integers as parameters but in the main function you make a call for that function with zero arguments..

1
2
3
	heartRates rate("Jennifer", "Morris", 8, 4, 1988, 2010);

	rate.displayInfo();



I couldnt figure out what the 'int y' represents. but you should know..
and if you'll call the function like so :

rate.displayInfo (175, 50, 1973 )

it should work
thank you both for your help....i actually just ended up having displayInfo() accept no arguments at all....thanks again.
I thought that I had the solution, however, I have one last problem. When I run the program, the age, target heart range and maximum heart rate print out as decimals!!! i can still run the program but i get two errors in the function "set targetHeartRate(int max)" that say "double to int possible loss of data" i believe because I am multiplying by a decimal. How can I perform the same calculation and get the age, target heart range, and maximum heart rate to print as an integer to the screen?


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
/*#include <iostream>
#include <string>
using namespace std;

class heartRates
{
	string first;
	string last;
	int month;
	int day;
	int year;
	int age;
	int curyear;
	int max;
	double hi;
	double lo;
	int c;
	int y;

public:
    heartRates (string, string, int, int, int, int);
	void setFirst(string);
	void setLast(string);
	void setMonth(int);
	void setDay(int);
	void setYear(int);
	void setcuryear(int);
	void setAge(int);
	void setTargetHeartRate(int);
	void setMaximumHeartRate(int);
	string getFirst();
	string getLast();
	int getMonth();
	int getDay();
	int getYear();
	int getAge();
	int getcuryear();
	int getMaximumHeartRate();
	int getTargetHeartRate(int);
	void displayInfo();

};*/



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
122
/*#include <iostream>
#include <string>
#include "heartRates.h"
using namespace std;

string heartRates::getFirst()
{
	return first;
}

string heartRates::getLast()
{
	return last;
}

int heartRates::getMonth()
{
	return month;
}

int heartRates::getDay()
{
	return day;
}

int heartRates::getYear()
{
	return year;
}

int heartRates::getcuryear()
{
	return c;
}

int heartRates::getAge()
{
	return age;
}

int heartRates::getMaximumHeartRate()
{
	return max;
}

int heartRates::getTargetHeartRate(int max)
{
	return hi;
	return lo;
}

void heartRates::setMaximumHeartRate(int max)
{
	max = 220 - age;
}
void heartRates::setTargetHeartRate(int max)
{
	hi = max * .85;
	lo = max * .5;
}

void heartRates::setFirst(string f)
{
	first = f;
}

void heartRates::setLast(string l)
{
	last = l;
}


void heartRates::setDay(int d)
{
	day = d;
}

void heartRates::setMonth(int m)
{
	month = m;
}

void heartRates::setYear(int y)
{
	year = y;
}

void heartRates::setcuryear(int c)
{
	curyear = c;
}

void heartRates::setAge(int age)
{
	age = c - y;
}


heartRates::heartRates (string f, string l, int m, int d, int y, int c)
{
	heartRates::setcuryear(c);
	heartRates::setDay(d);
	heartRates::setMonth(m);
	heartRates::setYear(y);
	heartRates::setFirst(f);
	heartRates::setLast(l);
	heartRates::setAge(age);
}

void heartRates::displayInfo()
{
	cout << "Your information is as follows:" << endl;
	cout << getLast() << ", " << getFirst() << endl;
	cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
	cout << "Current age is: " << getAge() << endl;
	cout << "Maximum heart rate is: " << getMaximumHeartRate() << endl;
	cout << "Target heart range is between: " << lo << " and " << hi << endl;
}



*/


1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*#include <iostream>
#include <string>
using namespace std;
#include "heartRates.h"

int main()
{

	heartRates calc("Jennifer", "Morris", 8, 4, 1988, 2010);

	calc.displayInfo();

	return 0;
}*/
i've tweaked it a bit in the header by changing double hi and double lo to int hi and int lo. Also, ive added int() around the calculations for hi and lo int the function definition for setTargetHeartRange() and setAge() but now i am getting some weird negative number for both values when i run the program (it is now error free according to the compiler). Im not sure if its the location of the value that is printing out instead of the value?

header:

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
/#include <iostream>
#include <string>
using namespace std;

class heartRates
{
	string first;
	string last;
	int month;
	int day;
	int year;
	int age;
	int curyear;
	int max;
	int hi;
	int lo;
	int c;
	int y;

public:
    heartRates (string, string, int, int, int, int);
	void setFirst(string);
	void setLast(string);
	void setMonth(int);
	void setDay(int);
	void setYear(int);
	void setcuryear(int);
	void setAge(int);
	void setTargetHeartRate(int);
	void setMaximumHeartRate(int);
	string getFirst();
	string getLast();
	int getMonth();
	int getDay();
	int getYear();
	int getAge();
	int getcuryear();
	int getMaximumHeartRate();
	int getTargetHeartRate(int);
	void displayInfo();

};/





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
122
123
124
/*#include <iostream>
#include <string>
#include "heartRates.h"
using namespace std;

string heartRates::getFirst()
{
	return first;
}

string heartRates::getLast()
{
	return last;
}

int heartRates::getMonth()
{
	return month;
}

int heartRates::getDay()
{
	return day;
}

int heartRates::getYear()
{
	return year;
}

int heartRates::getcuryear()
{
	return c;
}

int heartRates::getAge()
{
	return age;
}

int heartRates::getMaximumHeartRate()
{
	return max;
}

int heartRates::getTargetHeartRate(int max)
{
	return hi;
	return lo;
}

void heartRates::setAge(int age)
{
	age = int(c - y);
}

void heartRates::setMaximumHeartRate(int max)
{
	max = 220 - age;
}
void heartRates::setTargetHeartRate(int max)
{
	hi = int(max * .85);
	lo = int(max * .5);
}

void heartRates::setFirst(string f)
{
	first = f;
}

void heartRates::setLast(string l)
{
	last = l;
}


void heartRates::setDay(int d)
{
	day = d;
}

void heartRates::setMonth(int m)
{
	month = m;
}

void heartRates::setYear(int y)
{
	year = y;
}

void heartRates::setcuryear(int c)
{
	curyear = c;
}




heartRates::heartRates (string f, string l, int m, int d, int y, int c)
{
	heartRates::setcuryear(c);
	heartRates::setDay(d);
	heartRates::setMonth(m);
	heartRates::setYear(y);
	heartRates::setFirst(f);
	heartRates::setLast(l);
	heartRates::setAge(age);
}

void heartRates::displayInfo()
{
	cout << "Your information is as follows:" << endl;
	cout << getLast() << ", " << getFirst() << endl;
	cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
	cout << "Current age is: " << getAge() << endl;
	cout << "Maximum heart rate is: " << getMaximumHeartRate() << endl;
	cout << "Target heart range is between: " << lo << " and " << hi << endl;
}



*/





1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*#include <iostream>
#include <string>
using namespace std;
#include "heartRates.h"

int main()
{

	heartRates calc("Jennifer", "Morris", 8, 4, 1988, 2010);

	calc.displayInfo();

	return 0;
}*/





Topic archived. No new replies allowed.