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.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
kgprettyAuthor 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;
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.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

also add years in the param list.
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

kgprettyAuthor Commented:
Thanx.. how do I truncate a number?

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

int main () {
  double f = 3.14159;
  cout << f << endl;
  cout << f << endl;
  return 0;
The execution of this example shall display:

in your case,
cout << number << endl;
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

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.