Question

In: Computer Science

](Currency Exchange) You are given the exchange rate from Canadian to US dollars. You are asked...

](Currency Exchange) You are given the exchange rate from Canadian to US dollars. You are asked to convert an amount either from Canadian to US or vice versa based on the user's request. Write a C++ program that prompts the user to enter: a. the exchange rate from currency in Canadian dollars to US dollars b. either 0 to convert from Canadian to US or 1 to convert from US to Canadian (the program displays a message for invalid input) c. either the amount in Canadian or US dollars according to the request The program then calculates and displays the amount in either Canadian or US dollars according to the request. Here are sample runs: Rate from CAD to USD: 0.747 0 for CAD to USD or 1 vice versa: 0 CAD amount: 100 100 CAD is 74.7 US Rate from CAD to USD: 0.75 0 for CAD to USD or 1 vice versa: 1 US amount: 100 100 US is 133.33 CAD Rate from CAD to USD: 0.754 0 for CAD to USD or 1 vice versa: 5 Invalid input

Solutions

Expert Solution


/*C++ program that display the conversion from canadian to usd for 0
and usd to canadian for 1 .Then do the conversion and print the results on
console output window The program continues till user enters an invalid
input value.*/

//main.c
//include header file
#include<iostream>
using namespace std;
//start of main function
int main()
{
   //declare variables
   int userchoice;
   //set repeat to true
   bool repeat=true;
   double canadianDollars=0;
   double americanDollars=0;

   //constants for conversion
   const double CAD_TO_USD=0.747;
   const double USD_TO_CAD=1.36;
   cout<<"Rate from CAD to USD: 0.747"<<endl;
   cout<<"0 for CAD to USD"<<endl;
   cout<<"1 for USD to CAD"<<endl;
   //read userchoice
   cin>>userchoice;
   while(repeat)
   {
       //check if userchoice is 0
       if(userchoice==0)
       {
           cout<<"CAD amount:";
           cin>>canadianDollars;
           //convert candian to american dollars
           americanDollars=canadianDollars*CAD_TO_USD;

           cout<<canadianDollars<<" CAD is "<<americanDollars<<" US"<<endl;
       }
       //check if userchoice is 1
       else if(userchoice==1)
       {
           cout<<"USD amount:";
           cin>>americanDollars;
           //convert american dollars to candian dollars
           canadianDollars=americanDollars*USD_TO_CAD;

           cout<<americanDollars<<" USD is "<<canadianDollars<<" CAD"<<endl;
       }
       else
       {
           //set repeat to false to stop repetition of while loop
           repeat=false;

           cout<<"Invalid input"<<endl;
       }
       //prompt for input if repeat is true
       if(repeat)
       {
           cout<<"Rate from CAD to USD: 0.747"<<endl;
           cout<<"0 for CAD to USD"<<endl;
           cout<<"1 for USD to CAD"<<endl;
           cin>>userchoice;
       }
   }

   //pause console output on console
   //till user enters a key on keyboard
   system("pause");
   return 0;
}

-------------------------------------------Sample Run#------------------------------------------------


Related Solutions

- On April 17, 2018 the exchange rate between the Canadian dollar and the US dollars...
- On April 17, 2018 the exchange rate between the Canadian dollar and the US dollars was 1 CAD = 0.796 USD. On April 5, 2019 the exchange rate was 1 CAD = 0.780 USD. Did the Canadian dollar appreciate or depreciate and by what percent? (1 point) - Find the exchange rate in terms of US dollars per British pound if on April 5, 2019 the exchange rate between the US dollar and the Mexican peso was 1 USD...
If the supply of dollars in the market for foreign-currency exchange shifts left, then the exchange rate
  If the supply of dollars in the market for foreign-currency exchange shifts left, then the exchange rate rises and the quantity of dollars exchanged falls. rises and the quantity of dollars exchanged does not change. rises and the quantity of dollars exchanged rises. falls and the quantity of dollars exchanged does not change. If a country has a trade deficit It has positive net exports and positive net capital outflow. It has positive net exports and negative net capital...
Given a currency pair, what happens to the exchange rate if the foreign exchange market is...
Given a currency pair, what happens to the exchange rate if the foreign exchange market is in disequilibrium? Does it matter if the exchange rate is above or below the equilibrium rate? Understand what market forces drive the exchange rate back to equilibrium in both cases, whether or not the cases are different.
The exchange rate between Pounds and US dollars is determined by the intersection of the demand...
The exchange rate between Pounds and US dollars is determined by the intersection of the demand and supply curves for euros in terms of dollars. Explain how an increase in US inflation relative to English inflation will effect equilibrium exchange rates.
Assuming the exchange rate is the foreign currency price of dollars (x), use an appropriate diagram...
Assuming the exchange rate is the foreign currency price of dollars (x), use an appropriate diagram and describe the effect of a domestic increase in G (i.e., our government increases its spending) on the value of the foreign currency.
Where does the supply of dollars in the foreign-currency exchange market come from?
Where does the supply of dollars in the foreign-currency exchange market come from?            a.         from Canadian national saving            b.         from Canadian net capital outflow            c.          from domestic investment            d.         from foreign demand for Canadian goods
Find the historical exchange rate of US dollar to CHF (Switzerland) and explain if the currency...
Find the historical exchange rate of US dollar to CHF (Switzerland) and explain if the currency has appreciated or depreciated in relation to the US dollar. List some examples as to why this might have happened. For instance, an international event (one event is fine). Approach this from the event side, explore what happened to the exchange rate as an outcome of this particular event.
Analyze the currency for Hong Kong Dollars The currency exchange market is one that follows the...
Analyze the currency for Hong Kong Dollars The currency exchange market is one that follows the laws of supply and demand and the exchange rate is the price. Analyze the price change in terms of the forces of supply and demand.
Today is Jan. 31, 2021 and the current exchange rate between US dollar and Canadian dollar...
Today is Jan. 31, 2021 and the current exchange rate between US dollar and Canadian dollar is US$0.7946/CAD (U.S. is the home country). The current June 2021 Micro CAD/USD Futures exchange rate is US$0.7949/CAD. Contract size is CAD $10,000. For more information about this futures contract, please go to the website below: The risk-free rate in Canada is 0.15% per annum with continuously compounding. Assume all futures contracts expire in the last day of the month. What should the risk-free...
The exchange rate of a currency is the price paid in one country's currency for the...
The exchange rate of a currency is the price paid in one country's currency for the currency of another country. If a company in the United States sources parts from a company in Europe, dollars will need to be converted to euros to pay for the parts. This need to convert currency introduces uncertainty as to the actual cost of the parts, since the exchange rate at the time the price is quoted may be different from the rate when...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT