I'm a super new student learning c++ and created a small currency converter that takes a string for input for a country you are visiting. With the normal std::cin >> country; the program runs fine but won't read countries like "Dominican Republic". I tried using getline but that skips over the country input straight to the last else {} statement.
std::cout << "Enter how many US Dollars you want to convert: " << std::endl;
std::cin >> USD;
std::cout << "What country are you planning to visit?" << std::endl;
std::getline(std::cin, country);
if (country == "Canada") {
conversion = USD * 1.2074;
std::cout << USD << " US dollars converted into Canadian Dollars (CAD) is: " << std::endl;
std::cout << conversion << " Canadian Dollars" << std::endl;
std::cout << "Hit Y if you'd like to convert again or N to quit. " << std::endl;
std::cin >> again;
}
else {
std::cout << "Sorry, this converter only has major US tourist destinations." << std::endl;
std::cout << "Please try another country. Hit Y if you'd like to try again or N to quit.";
std::cin >> again;
}
How can I adjust the code to actually receive the input before running the else branch? Thank you guys!