C++ program to demonstrate default arguments - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, August 21, 2017

C++ program to demonstrate default arguments

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


Ouput:

Final Value=1005.68

Final Value=3712.93

Program:
#include<iostream>
using namespace std;

int main(int argc, char** argv)
{
   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;

}

No comments:

Post a Comment