[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

mutliple functions??

Posted on 2004-10-26
7
Medium Priority
?
233 Views
Last Modified: 2012-05-05
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 ().
0
Comment
Question by:kgpretty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
dennis_george earned 180 total points
ID: 12417849
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
 

Author Comment

by:kgpretty
ID: 12418379
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
 
LVL 9

Expert Comment

by:jhshukla
ID: 12418695
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:jhshukla
ID: 12418699
also add years in the param list.
0
 
LVL 5

Expert Comment

by:dennis_george
ID: 12419362
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 Comment

by:kgpretty
ID: 12429253
Thanx.. how do I truncate a number?

eg. 16.66666666666666 to 16.67
0
 
LVL 9

Assisted Solution

by:jhshukla
jhshukla earned 120 total points
ID: 12430449
#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

in your case,
cout.precision(4);
cout << number << endl;

http://www.cplusplus.com/ref/iostream/ios_base/index.html
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question