If 2 statements

I don't know where I went wrong

#include <iostream>
using namespace std;

int main(){
int num1;
int num2;
char con1;
char con2;
char USD;
char BBD;



cout << "Currency Converter" << endl;
cout << " USD,BBD can all be converted" << endl;
cout << "Please input the dollar amount then press enter";
cin >> num1;
cout << "enter the currency it is curently in then press enter: ";
cin >> con1;
cout << "Now enter what you want to convert it to: ";
cin >> con2;
if (con1 == "USD" && con2 == "BBD")
{ num2 = num1 * 2.02;
cout << num2;
}
else if (con1 == "BBD" && con2 == "USD")
{ num2 = num1 * 0.5;
cout << num2;
}
else
cout << "invalid input";

return 0;
}
char is a 1 byte / integer. it is NOT a string, and its not even a unicode compatible character. It can store ascii type letters or small integer values.
con1 cannot ever be "USD" that is 3 letters, 3 bytes, a text string.

you want
#include <string>
string con1;
if (con1 == "USD")

later on you may see old C style code that uses arrays of char as 'strings'. That is very hands-on and not worth talking about today.


now that you know what the problem is, you should see if your compiler was trying to warn you about it and make sense of the words it uses. Learning to read your errors and warnings takes some getting used to.
Last edited on
You are truly the greatest of all time.
Thank You
Topic archived. No new replies allowed.