#include #include using namespace std; int main() { long USD, maxUSD; // Amount in USD double rate; // Exchange rate USD <-> MYR cout << "\n* * * * TABLE OF EXCHANGE * * * *\n "; cout << "* United State Dollar (USD) to Malaysia Ringgit (MYR) *\n\n"; cout << "\nPlease give the rate of exchange: "; cout <<" \n\n 1 USD in RM MYR: "; cin >> rate; cout << "\n Please enter the USD you want to change: "; cin >> maxUSD; // Outputs the table & Titles of columns: cout << "\n If Rate Now is : " << rate << endl; cout << "\n so, USD to RM exchange is : "<< endl; cout << '\n'<< setw(12) << "USD" << setw(20) << "MYR"; cout << '\n'<< setw(16) << "---------------------------------------------" ; cout << '\n'<< setw(24) << " >>> " ; // Formatting RM-MYR: cout << setprecision(2) << endl; long lower, upper, // Lower and upper limit step; // Step width // The outer loop determines the actual // lower limit and the step width: for( lower=1, step=1; lower <= maxUSD;  step*= 10, lower = 2*step)  {  for( USD = lower, upper = step*10;  USD <= upper && USD <= maxUSD; USD+=step)  { cout << setw(12) << USD; cout << setw(20) << USD*rate << endl}  } // The inner loop outputs a "block":  cout << '\n'<< setw(16) << "---------------------------------------------" ;  cout << "\n\n"; return 0; } 4.7.1 explain what the program does?  4.7.2 What is the output.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section: Chapter Questions
Problem 1PP
icon
Related questions
Question

4.7 for repetition 


#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long USD, maxUSD; // Amount in USD
double rate; // Exchange rate USD <-> MYR
cout << "\n* * * * TABLE OF EXCHANGE * * * *\n ";
cout << "* United State Dollar (USD) to Malaysia Ringgit (MYR) *\n\n";
cout << "\nPlease give the rate of exchange: ";
cout <<" \n\n 1 USD in RM MYR: ";
cin >> rate;
cout << "\n Please enter the USD you want to change: ";
cin >> maxUSD;
// Outputs the table & Titles of columns:
cout << "\n If Rate Now is : " << rate << endl;
cout << "\n so, USD to RM exchange is : "<< endl;
cout << '\n'<< setw(12) << "USD" << setw(20) << "MYR";
cout << '\n'<< setw(16) << "---------------------------------------------" ;
cout << '\n'<< setw(24) << " >>> " ;
// Formatting RM-MYR:
cout << setprecision(2) << endl;
long lower, upper, // Lower and upper limit
step; // Step width
// The outer loop determines the actual
// lower limit and the step width:
for( lower=1, step=1; lower <= maxUSD;
 step*= 10, lower = 2*step)
 {
 for( USD = lower, upper = step*10;
 USD <= upper && USD <= maxUSD; USD+=step)
 {
cout << setw(12) << USD;
cout << setw(20) << USD*rate << endl}
 } // The inner loop outputs a "block":
 cout << '\n'<< setw(16) << "---------------------------------------------" ;
 cout << "\n\n";
return 0;
}

4.7.1 explain what the program does? 
4.7.2 What is the output. 

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr