I have a simple C++ issue with my if statements, the program runs the values as the initial if parameters rather than performing the else if. Also I tried to code so that if the result of the function equaled 1 it would type out a grammatically correct statement is there a better way of doing that other than using another if statement?
int main()
{
cout << "Please type out amount and currency type to convert to dollars.\n";
double val1;
string currency;
double result = 0;
cin >> val1 >> currency;
if (currency == "yen" || "y")
{
result = val1/100;
if (result == 1) {
cout << "You have " << val1 << "yen which equals \n"
<< result << ", dollar.";
}
else
cout << "You have " << val1 << "yen which equals \n"
<< result << ", dollars.";
}
else if (currency == "euros" || "e")
{
result = val1*1.25;
if (result == 1) {
cout << "You have " << val1 << "euros which equals \n"
<< result << ", dollar.";
}
else
cout << "You have " << val1 << "euros which equals \n"
<< result << ", dollars.";
}
else if (currency == "pounds" || "p")
{
{
result = val1 *1.2;
if (result == 1) {
cout << "You have " << val1 << "pounds which equals \n"
<< result << ", dollar.";
}
else
cout << "You have " << val1 << "pounds which equals \n"
<< result << ", dollars.";
}
}
else
cout << "I didn't understand, please try again.\n";
}
Aucun commentaire:
Enregistrer un commentaire