Write a function to calculate the exchange rate, C/C++ Programming

Assignment Help:

Write a function to calculate the exchange rate of pounds to dollars 

Answer

      Td = 2xTp
 
The parameter passed over is the number of pounds and returned the value in dollars

    float  convert (float x )
    { 
      float  y ;
/*A function which converts pounds   measure X to a dollars measure*/
    /*The parameter x is real and a real value y  is  returned*/
       y = 2.0  * x;
       return (y);
    }
The program which calls the function would be
    include
    include
    include
    include
    include
    void  main()
    {
    char prompt;
     float  a, b;
    printf("please enter in your value in pounds  \n\r");
     scanf("%f",&a);
     b= convert(a);
     printf("The value in dollars  is %5.3f \n\r",b);
     b= convert(3.0);
     printf("The value in dollars of 3 pounds   is %5.3f \n\r",b);   
    printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
    }

 Here the program requests the value of a in pounds, then executes function 'Convert'. This causes the program to go to the function statement, pass the variable a, to it and the output is passed back to the program. The output is then assigned to variable b and printed out. It is possible to pass a value over instead of a variable. The only amendment we have to make is to add the prototype to the program i.e.

    float convert (float);
 
This describes the type of variables passed to and from the function. Therefore the complete program and function is shown below 
 
    include
    include
    include
    include
    include
    float  convert (float);
    void main()
    {
    char prompt;
     float  a, b;
    printf("please enter in your in pounds \n\r");
     scanf("%f",&a);
     b= convert(a);
     printf("The value in dollars is %5.3f \n\r",b);
     b= convert(3.0);
     printf("The value in dollars  of 3 pounds is %5.3f \n\r",b);   
                        printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
    }
 
    float  convert (float x )
    { 
      float  y ;
/*A function which converts pounds   measure X to a dollars measure*/
    /*The parameter x is real and a real value y  is  returned*/
     
        y = 2.0  * x;
       return (y);
    }


Related Discussions:- Write a function to calculate the exchange rate

Functions, write a program to calculate gross salary and net salary using h...

write a program to calculate gross salary and net salary using hra da pf in c++

Queue - c++ program, Queue - C++ program: Write a program to show the ...

Queue - C++ program: Write a program to show the basic operations on queue. namespace stack {  const int max_size = 200;  char v(max_size);  int top=0;  void pu

Luminous Jewels - The Polishing Game, within 2 mins give me answer pllzzzzz...

within 2 mins give me answer pllzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Plz reply on [email protected], You are to implement a code cracking ...

You are to implement a code cracking system. The system will deploy four processes (p1,p2,p3 & p4) to try to guess the password of an encrypted code. For encryption, we consider th

How to write an inline class member function, How to write an inline class ...

How to write an inline class member function In addition to global functions, you may request that non-static member functions of a class be inlined.  The normal method of doin

Dynamic memory management, C and C++ require explicit dynamic memory manage...

C and C++ require explicit dynamic memory management, using new and delete or malloc() and free(). It is helpful to understand where variables exist (usually the stack or the he

Decodethecode, how to decode the numerals to string..

how to decode the numerals to string..

Program decision making instructions, Within programs we very often want to...

Within programs we very often want to execute a different section of code, depending upon various conditions within C the If statement is used to achieve this. The If statement con

What is an iterator class?, A: A class which is used to traverse through th...

A: A class which is used to traverse through the objects maintained through a container class. There are _ve categories of iterators: output iterators, input iterators, forward ite

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd