trying to write a simple program that will figure a mort payment but this program is not compiling ... I use Codeblockers and it shows me where the errors are but not sure how to fix this to run ...it shows I have 6 errors .... the first in line 75 and the void main statement ...... I am open to suggestions, if anyone has any..
Please post the errors exactly as they appear in your development environment.
Also the problem on line 75 is that in a C++ program main() must be defined to return an int, not void, and you should return an int from this function.
In both of these methods you are NOT returning the values you have calculated.
- cout <<"Total Pay Back: $" << (mortgage.pay*mortgage.getYears*12) <<endl;
You need to call functions by ending the call in brackets, which you are not doing in some of your calls, e.g. getYears().
EDIT: I don't see any class inheritance, so i'm not sure why it's in your thread title.
sorry-let me elaborate - 1st programming class with no programming experience here so I am very unclear what you are referring to ..please correct me if I am wrong in my thoughts here ....
so it should be...." return payment " instead of "return pay" ? ( and return term instead of return tm)
also as far as your brackets to end the get Years... are you saying this should read like this?
either way I still get the error of the unqualified -id for line 76 now (since I moved everything) and the class listed is payments with what type of payment listed as mortgage payment for the inherit question. Again please correct me if I mis understood or I am interpreting this incorrectly
Thank you. Sure: here is the current text..added the changes I "thought" you were suggesting and the brackets too.......feeling at this point I have the program I just need to figure out how to fix it so I have the output that I am looking for once a user inputs the requested info.
I don't see that error when I compile your code. The only error message I receive are:
main.cpp||In function ‘int main()’:|
main.cpp|17|error: ‘float Payment::pay’ is private|
main.cpp|101|error: within this context|
main.cpp|17|error: ‘float Payment::pay’ is private|
main.cpp|104|error: within this context|
Also if you used some kind of indentation you might be able to read your program easier:
You cannot access your private pay member variable like this. You should write an accessor (or 'getter') method and declare it in your public section with your other methods:
1 2 3 4
float Payment::getPay()
{
return pay;
}
Then your line of code becomes this: [code]cout << "Monthly payment: $" << mortgage.getPay() << endl;[/code]