Question:
Help with C++ program....?
Nour
2009-02-01 22:16:13 UTC
I'm trying to run this program but I keep getting errors. Here's the program and I'll post the errors right after.
// Calculates amount of Investment after Interest Rate.
//

#include
#include
using namespace std;
double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years); //prototype//


int main()
{ double investmentAmount;
double monthlyInterestRate;
int years;
cin >> investmentAmount;
cin >> monthlyInterestRate;
cin >> years;
cout << futureInvestmentValue(investmentAmount*pow(1+monthlyInterestRate, years*12);
return 0;
}

double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
{
futureInvestmentValue= investmentAmount*pow(1+ monthlyInterestRate, years*12);
return futureInvestmentValue;
}

1>c:\users\nour\desktop\things\stuff\assignment 4\assignment 4\assignment 4.cpp(17) : error C2143: syntax error : missing ')' before ';'
1>c:\users\nour\desktop\things\stuff\assignment 4\assignment 4\assignment 4.cpp(17) : error C2660: 'futureInvestmentValue' : function does not take 1 arguments
1>c:\users\nour\desktop\things\stuff\assignment 4\assignment 4\assignment 4.cpp(23) : error C2659: '=' : function as left operand
1>c:\users\nour\desktop\things\stuff\assignment 4\assignment 4\assignment 4.cpp(24) : error C2440: 'return' : cannot convert from 'double (__cdecl *)(double,double,int)' to 'double'
Four answers:
Allison D
2009-02-01 22:24:41 UTC
Firstly, you should poost the full part of this line: cout << futureInvestmentValue(investmentAmount*p... years*12); as there is something going on inside the parenthesis, but it's wrong as it is. When you call the function futureInvestmentValue, you are leaving out the monthlyInterestRate and years, which is why it's saying that function does not take 1 argument (you're passing 1, it takes 3).



Within the function futureInvestmentValue, you are using the variable 'futureInvestmentValue', which you cannot do because it is the name of the function, that's the error "function as left operand".



You should change your '1' to 1.0 and your 12 to 12.0 because there is type casting going on that you do not want. You should not be mixing integers (1) with doubles unless you know what the end result is going to be in, just use the same types in operations like that. This may not be such a big deal, but it's just good practice.



I will be able to help more when you post that full line, I think it is causing more problems.
anonymous
2009-02-01 22:28:23 UTC
1. futureInvestmentValue is a function so you cant do

futureInvestmentValue = investmentAmount*pow(1+ monthlyInterestRate, years*12);





2. futureInvestmentValue(investmentAmount*p... years*12);

futureInvestmentvalue takes three parameters and there you are only using 1 remember they are seppareted by comas (x,y,z)

3. p is not declared



4. This is not a error but since you are using c++ use cmath instead of math.h



I dont know if that are the only errrors
v3ks
2009-02-01 22:26:59 UTC
: error C2440: 'return' : cannot convert from 'double (__cdecl *)(double,double,int)' to 'double'



I believe this error is produced by using the functions name as a variable inside the function ....

And when you do a return futureInvestmentValue. You need to change the variable name, or just do this:

return (investmentAmount*pow(1+ monthlyInterestRate, years*12));
MooseBoys
2009-02-01 22:22:13 UTC
cout << futureInvestmentValue(...

This line has a syntax error somewhere, but Yahoo cut it off so I can't see it.



futureInvestmentValue= investmentAmount*pow(...

This line attempts to assign a value to a function name. Change the function to:

return investmentAmount*pow(1+ monthlyInterestRate, years*12);


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...