Sunday, 30 June 2013

Write a C++ Program to demonstrate default argument

//Program demonstrating the use of default argument//

//Author :- Ashish Mishra//

//Date :- 30/06/2013//

#include<iostream>

using namespace std;

int main()
{
float amount;

float value (float p, float n, float r = 0.15);     //Prototype declaration

        amount = value (5000.00 , 5);                //Default for the 3rd argument
  
cout<<"\n Final Value = "<<amount<<"\n";

return 0;

}

float value (float p, float n, float r)
{
int year = 1;
float sum = p;

while ( year <=n)
{
sum = sum*(1+r);
year= year + 1;

}

return (sum);
}

The output of the program is "Final Value = 10056.80"


No comments:

Post a Comment

Thank you for commenting.