views
Download Microsoft Visual Studio. Go to visualstudio.microsoft.com and download the Community version of Visual Studio to start writing your C++ Currency Converter.
Open up Visual Studio and create a project.
Add a .cpp in your source files to start coding.
Declare your libraries and namespace. To make sure everything run, we must use include for consio.h, cstdlib, fstream, iomanip, iostream and string.
#include
Create the main function where you are going to write the code in. Write all the codes inside the main function. int main() { }
Declare Double variables. Make USD and Rate double , as well as declare the currency rate. as in C++ Double stores real numbers. Double variable.png double usd; double rate; double euro; rate = 0.85;
Declare two columns. Create two columns where right justify label and left justified values. 2columns.png const int COLMFT1 = 35; const int COLMFT2 = 15;
Format the real numbers. To limit the amount of numbers after the decimal point use setprecision, in the example use set the sets the amount of decimal places to 2.Realnumberset2.png cout << fixed << setprecision(2);
Add an application header to welcome the user to the currency converter. Ex: “Welcome to C++ Currency Converter” Welcome header.png cout << "“Welcome to C++ Currency Converter" << endl;
Prompt user input. Use cout and cin statement to prompt the user for information. cout << cout << setw(COLMFT1) << left << "Enter a value (US dollars): "; cin >> usd; cout << endl;
Show User input on screen. Show the user number of the user input on screen Userinput2.png cout << setw(COLMFT1) << left << "US dollars: "; cout << setw(COLMFT1) << right << usd << endl;
Show the conversion rate of currency on screen. Ex: $1 USD = $0.85 Euro cout << setw(COLMFT1) << left << "Conversion rate(per US dollar): "; cout << setw(COLMFT1) << right << rate << endl;
Calculate the given number with the rate. write a equation where it calculate the USD to euro. CalConversion rate.png euro = usd * rate;
Show the converted currency.
Add a closing statement to the application. Use cout statement to add a closing to the application. cout << "\n--------------------------- " << endl; cout << "\nEnd of Rate Converter" << endl;
Run the Windows debugger to make sure the application is running correctly. Click on “Local Windows Debugger” or Press F5 on the keyboard to run the application.
Comments
0 comment