I need a c++ program that converts U.S dollar amount to Zambian Kwacha, Belize,
ID: 3781638 • Letter: I
Question
I need a c++ program that converts U.S dollar amount to Zambian Kwacha, Belize, and Hong Kong dollars. I have the following code, but its not working corrrectly.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
const double ZAMBIANKWACHA_PER_DOLLAR = 9950;
const double BELIZE_PER_DOLLAR = 2.10;
const double HONG_KONG_PER_DOLLAR = 7.76;
double dollars, zambiankwacha, belize, hongkong;
cout << setprecision(2) << fixed;
cout << "Enter dollar amount: ";
cin >> dollars;
zambiankwacha = dollars * ZAMBIANKWACHA_PER_DOLLAR;
belize = dollars * BELIZE_PER_DOLLAR;
hongkong = dollars * HONG_KONG_PER_DOLLAR;
cout << "-------Conversion------- ";
cout << "$" << dollars << " = " << zambiankwacha << " zambiankwacha ";
cout << "$" << dollars << " = " << belize << " belize ";
cout << "$" << dollars << " = " << hongkong << "Hong Kong " ;
system("pause");
return 0;
}
Explanation / Answer
Simply, remove system("pause") from the program and it will run:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
const double ZAMBIANKWACHA_PER_DOLLAR = 9950;
const double BELIZE_PER_DOLLAR = 2.10;
const double HONG_KONG_PER_DOLLAR = 7.76;
double dollars, zambiankwacha, belize, hongkong;
cout << setprecision(2) << fixed;
cout << "Enter dollar amount: ";
cin >> dollars;
zambiankwacha = dollars * ZAMBIANKWACHA_PER_DOLLAR;
belize = dollars * BELIZE_PER_DOLLAR;
hongkong = dollars * HONG_KONG_PER_DOLLAR;
cout << "-------Conversion------- ";
cout << "$" << dollars << " = " << zambiankwacha << " zambiankwacha ";
cout << "$" << dollars << " = " << belize << " belize ";
cout << "$" << dollars << " = " << hongkong << "Hong Kong " ;
return 0;
}
Reason:
system("pause") is generally used by learning programmers to pause the system, so that the programmers can read their output.
system("pause") runs windows command-line "pause" and wait for programmers input to execute the program further.
Good way to do is run the program in debug mode, and put a breakpoint at the end of the program.
So, it is a platform specific thing, and should be used only in windows. There might be possibilities that it runs on other platforms, but in those IDE(s) which supports virtualization.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.