Accepting Specific strings

I am quite new to programming in Cpp and I cannot figure out how to get the program to deny "B" as a value for cat. I want it to only accept "Ba". Is there way to get it to only accept certain strings and not parts of them?
#include <iostream>

using namespace std;
string cat;
float catc;

int main ()
cin cat;
if (cat == "Ba") //this part also accepts "B" and "a", I want it only to accept
//"Ba" so that it will skip over this statement and go to the else if statement.
cout << "cat = 5";
else if (cat == "B")
cout << "cat = 3";
For one, your line 7 should be

cin >> cat;

But when I compile the program after that fix, there are no issues. The line you complain about accepts only Ba.
Last edited on
Topic archived. No new replies allowed.