Feb 1, 2011 at 7:38pm UTC
Trying to calculate exchange rate and the program keeps calculating first if statement even when currencyType != 1. I'm new to programming so I'm sure im overlooking something small. Help please?!
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
//declare variables
double USD;
const double EUR = 0.72508;
const double RUP = 45.6814;
const double YEN = 81.4614;
double currencyType;
double exchangeRate;
//prompt user for input
cout << "Enter U.S. Dollar amount: ";
cin >> USD;
cout << endl;
cout << "Choose which currency to convert to: " << endl;
cout << endl;
cout << "1: Euro" << endl << "2: Indian Rupee" << endl << "3: Japanese Yen\n" << endl;
cout << "Enter Appropriate Number: ";
cin >> currencyType;
cout << endl;
//calculate exchange rate
if ( currencyType = 1 )
{
exchangeRate = USD * EUR;
cout << "The amount in Euro is: " << exchangeRate <<endl;
}
else if ( currencyType = 2 )
{
exchangeRate = USD * RUP;
cout << "The amount in Indian Rupees is: " << exchangeRate << endl;
}
else if ( currencyType = 3 )
{
exchangeRate = USD * YEN;
cout << "The amount in Japanese Yen is: " << exchangeRate << endl;
}
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Feb 1, 2011 at 7:41pm UTC
if (currencyType = 1)
should be
if (currencyType == 1)
for all comparisons. And currencyType should be an int because all the options are ints.
Feb 1, 2011 at 7:42pm UTC
I knew it was something small. Thank you for your help.
Feb 1, 2011 at 10:39pm UTC
someday they are going to have to change that comparison operator.