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;
}
Post A Comment:
0 comments: