# mutliple functions??

Should I place multiple program defined functions in my C++ code?

I have to find the maturity value for four different rates [4%, 5%, 6%, 7%] using this expression:

maturity4 = principal * pow((1 + rate/100) ,years);

The question states that the formula should be calculated in a separate function, but the output should be in main ().
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I think its a homework question... so I will not help you with code..... but we can guide you how to do it.....

I think you have been asked to create four functions, each with different names.... e.g. calculate_Maturity4, calculate_Maturity5, calculate_Maturity6, ....

and each function will have separate rates... calculateMaturity4 will be return a value calculated with rate = 4%
e.g. it will return principal * pow((1 + 4/100), years)....

Hope you got it
Dennis
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Ok.. I guess that answered my question - multiple functions.

When I'm displaying the answer.. and I have mat_val1 as the function name, I put this in right.. between the string and end line:

cout << "Maturity value with 4%: " << mat_val1 << endl;
0
Commented:
don't know if you want to do this or not:
float calculateMaturity(float principal, float rate){
...
}

then call the function with different principals & rates as arguments.
0
Commented:
also add years in the param list.
0
Commented:
If you are using global principal and year variable then its ok ... but with brackets

float mat_val1() ; // function declaration

cout << "Maturity value with 4%: " << mat_val1() << endl;

else as jhshukla said you can pass it to the function

cout << "Maturity value with 4%: " << mat_val1(principal, year) << endl;  // as rate is fixed for each function

Dennis
0
Author Commented:
Thanx.. how do I truncate a number?

eg. 16.66666666666666 to 16.67
0
Commented:
#include <iostream>
using namespace std;

int main () {
double f = 3.14159;
cout.precision(5);
cout << f << endl;
cout.precision(10);
cout << f << endl;
return 0;
}
The execution of this example shall display:
3.1416
3.14159

cout.precision(4);
cout << number << endl;

http://www.cplusplus.com/ref/iostream/ios_base/index.html
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.