Programming Challenge Chapter 3 – Q #11 Currency – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #11 Currency – Tony Gaddis – Starting Out With C++



Problem: -

Write a program that will convert U.S. dollar amounts to Japanese yen and to euros, storing the conversion factors in the constants YEN_PER_DOLLAR and EUROS_PER_DOLLAR. To get the most up-to-date exchange rates, search the Internet using the term currency exchange rate . If you cannot nd the most recent exchange rates, use the following:

                                              1 Dollar = 83.14 Yen 

                               1 Dollar = 0.7337 Euros

Format your currency amounts in fixed-point notation, with two decimal places of precision, and be sure the decimal point is always displayed.


Solution: -

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

      float const YEN_PER_DOLLAR = 83.14,

            EUROS_PER_DOLLAR = 0.73337;

 

      float us_dollar;

      float yen = 0.0, euro = 0.0;

 

      cout << "Enter Ammount In US Dollars:  $";

      cin >> us_dollar;

 

      yen = us_dollar * YEN_PER_DOLLAR;

      euro = us_dollar * EUROS_PER_DOLLAR;

 

      cout << setprecision(2) << showpoint << fixed;

      cout << "$" << us_dollar << " into Yens are  " << yen << "  Yens" << endl;

      cout << "$" << us_dollar << " into Euros are " << euro << " Euros" << endl;

 

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution

  1. Declare two float constants and initialize given values.
  2. Declare a float variable for input.
  3. Declare another two float variable for calculation.
  4. Take input from the user by using cin.
  5. Calculate the values by using given values.
  6.  In last, display output on the screen.
  7. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks! 



Post a Comment

0 Comments