Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Programming » C++ Programming » Programs » Functions » CPP program to demonstrate the use of default arguments
Suryateja Pericherla Categories: Functions. No Comments on CPP program to demonstrate the use of default arguments
2.7
(9)

In this article we will look at implementing a CPP program to demonstrate the use of default arguments. A C++ program is provided below to illustrate the use of default arguments for simple interest function. Program is as follows:

#include <iostream>
using namespace std;
float si(int p, int n, int r=5)
{
	return (p*n*r)/100;
}
int main()
{
	int p, n, r;
	cout<<"Enter principal amount: ";
	cin>>p;
	cout<<"Enter duration (in years): ";
	cin>>n;
	cout<<"Enter rate of interest: ";
	cin>>r;
	cout<<"Simple interest = "<<si(p, n, r);
	cout<<"Simple interest = "<<si(p, n);
	return 0;
}

 

Input and output for the above program are as follows:

Enter principal amount: 10000
Enter duration (in years): 5
Enter rate of interest: 10
Simple interest = 5000
Simple interest = 2500

 

How useful was this post?

Click on a star to rate it!


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory