Expression Must Have Class Type Error

Hi,
I'm doing an assignment that calculates the future value using the compound interest formula. This is a OOP code. I've set up the class but I'm having a problem within the main program. I keep getting an error message for lines 73 and 74 of the code.

Example:
line 74 << ci.getPrinc()
line 75 << ci.calcFV() << endl;

error: "expression must have a class type" (both lines, ci. underlined red)

Complete code including class:

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

//Constructor 
class CompoundInt
{
private:
	double princ, rate, frequency, time, fv, compoundPeriod;
public:
	//constructor
	CompoundInt(double p, double r, double f, double t, double n)
	{
		princ = p;
		rate = r;
		frequency = f;
		time = t;
		compoundPeriod = n;

	}
	//getters
	double getPrinc() {
		cout << "Enter the principal amount:";
		cin >> princ;
		return princ;
	}

	double getRate() {
		cout << "Enter the rate:";
		cin >> rate;
		return rate;
	}

	double getFrequency() {
		cout << "Enter the frequency:";
		cin >> frequency;
		return frequency;
	}

	double getTime() {
		cout << "Enter the time:";
		cin >> time;
		return time;
	}

	double getCompoundPeriod() {
		cout << "Enter the compound period:";
		cin >> compoundPeriod;
		return compoundPeriod;
	}

	//setters
	void setPrinc(double p) { princ = p; }
	void setRate(double r) { rate = r; }
	void setFrequency(double f) { frequency = f; }
	void setTime(double t) { time = t; }
	void setCompoundPeriod(double n) { compoundPeriod = n; }

	//calculation
	double calcFV() {
		double	fv = princ * pow((1 + (rate / compoundPeriod)), (time * compoundPeriod));
		return fv; 

	}

};


int main()
{
	CompoundInt ci(double princ, double rate, double frequency, double time, double fv, double compoundPeriod);
	cout << "Principle at "
        << ci.getPrinc()
	<< ci.calcFV() << endl;

	system("pause");
	return 0;
}

//End Code  


How can I fix these errors? All Help is appreciated.
Last edited on
closed account (E0p9LyTq)
PLEASE use code tags, they will make it easier to read and understand your code.

http://www.cplusplus.com/articles/jEywvCM9/

Hint: you can edit your post and add them.

What are the exact errors you are receiving?

I can see your getPrinc() method is not output stream friendly, you are asking for an input as well as returning a double.

You are getting two errors from one problem. That is not unusual.
Thanks for the link. The error i get comes from lines 74 and 75. The error is "expression must have a class type". You said the getPrinc() method is not output stream friendly. Do i ask for user input in the main()?
Topic archived. No new replies allowed.