I am now writing a new program, a modification of a program I have done before but now with arrays. It is a currency conversion program that converts four currencies. User inputs the starting currency and the program will display all four of the currency conversions for the amount the user input. I have the arrays set up, and it works on USD for dollars fine, but something is wrong with it when I try to test it using the latter three currencies. It does not display the preceding columns of the array. (i.e. when I test JPY for yen, it only displays three conversions, and does not display the first, EUR for euros displays only two conversions, etc.) Can someone help point me in the right direction? Thank you in advance for your expertise.
And I am sorry about not having line numbers, my program I use for school has line numbers on it, but they wont let me copy them with the code for some reason. If there is anything such as
type thing when I post code to the site, plz let me know. Thanks.
// currency4.cpp
// Takes an amount in U.S. dollars and converts it to euros, yens, and rupees, or vice versa
// The user inputs the symbol of the starting currency and the amount to be converted
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string symbol1 = "USD", symbol2 = "USD";
const int NUMOFROWS = 4;
const int NUMOFCOL = 4;
double matrix[NUMOFROWS][NUMOFCOL] = {
{1, 109.427, 0.688021, 39.3299},
{0.00913794, 1, 0.00628664, 0.359449},
{1.45313, 158.907, 1, 57.1616},
{0.0254259, 2.78235, 0.0174925, 1}
};
int row;
int col;
double newamnt;
double amount, result, rate;
{
cout << "This is a conversion program for U.S. dollars into euros,yens, and rupees or vice versa" << endl;
// get input
cout << "Please enter the three-letter symbol of the original currency: " << endl;
cout << "USD for Dollars" << endl;
cout << "JPY for Yen" << endl;
cout << "EUR for Euros" << endl;
cout << "INR for Rupees" << endl;
cin >> symbol1;
cout << endl;
cout << "Please enter the amount to be converted: ";
cin >> amount;
if (symbol1 == "USD" || symbol1 == "usd")
{
for (row = 0; row < NUMOFROWS; row++)
{
for (col = 0; col < NUMOFCOL; col++)
newamnt = (amount * matrix[row][col]);
cout << newamnt << endl;
}
}
if (symbol1 == "JPY" || symbol1 == "jpy")
{
for (row = 1; row < NUMOFROWS; row++)
{
for (col = 0; col < NUMOFCOL; col++)
newamnt = (amount * matrix[row][col]);
cout << newamnt << endl;
}
}
if (symbol1 == "EUR" || symbol1 == "eur")
{
for (row = 2; row < NUMOFROWS; row++)
{
for (col = 0; col < NUMOFCOL; col++)
newamnt = (amount * matrix[row][col]);
cout << newamnt << endl;
}
}
if (symbol1 == "INR" || symbol1 == "inr")
{
for (row = 3; row < NUMOFROWS; row++)
{
for (col = 0; col < NUMOFCOL; col++)
newamnt = (amount * matrix[row][col]);
cout << newamnt << endl;
}}
}
return 0;
}