Write a C++ program to demonstrate default arguments with a simple example.

Program Code:
#include<iostream.h>
int main()
{
float amount;
float value(float p,int n,float r=0.15);
amount=value(500.00,5);
cout<<"\nFinal Value="<<amount<<"\n";
amount=value(1000.00,5,0.30);
cout<<"\nFinal Value="<<amount<<"\n";
return 0;
}
float value(float p,int n,float r)
{
int year=1;
float sum=p;
while(year<=n)
{
sum*=(1+r);
year+=1;
}
return sum;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: