C++ problems with cin, cout and the if statement.
Hey guys, I am pretty new to this but thought this would be the best place to start. I am trying to make a piece of code that when the letter a is input, it will display "4x". Likewise when the letter b is input it will display "6x^2". It works perfectly when I input 'a' but for some reason whenever I input 'b' it displays "No Output". All help would be greatly appreciated! I've tried doing it 2 ways, but neither work. #include <iostream> #include <cctype> #include <cmath> using namespace std; int main() { char a; char b; cin >> a; cin >> b; if (a == 'a'|| a == 'A') cout << "4x"; else if (b == 'b'|| b == 'B') cout << "6x^2"; } Method 2 : #include <iostream> #include <cctype> #include <cmath> using namespace std; int main() { char a; cin >> a; if (a == 'a'|| a == 'A') cout << "4x"; char b; cin >> b; if (b == 'b'|| b == 'B') cout << "6x^2"; }