Still continues

#include <iostream>
#include <string>
using namespace std;

int main()

{
setlocale(LC_ALL, "");
int avstand;
string forhallande;
cout << "Är du ensamstående (Ja/Nej)? ";
cin >> forhallande;
if(forhallande == "Ja", "ja", "jA", "JA")
{
cout << "Hur långt har du till jobbet?" << endl;
cin >> avstand;
if(avstand > 50)
{
cout << "Ja du har rätt till avdrag" << endl;
}
}
else if(forhallande == "Nej", "nEj", "nEJ", "NEj", "NEJ", "nej", "NeJ")
cout << "Hur långt har du till jobbet?" << endl;
cin >> avstand;
if(avstand > 50)
{
cout << "Ja du har rätt till avdrag" << endl;
}

system("pause");
return 0;

}
--------------------------------------------------------------------------------
Why isn't this working. It continues after the 2nd if.
do not use the comma when it comes to comparing. The effect is that it effectively compares only with the very last expression ("JA" and "NeJ")

furthermore this
1
2
else if(forhallande == "Nej", "nEj", "nEJ", "NEj", "NEJ", "nej", "NeJ")
cout << "Hur långt har du till jobbet?" << endl;
is one expression. the rest is outside. Use { }


Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
I see you're trying to account for all possible combinations of upper- and lowercases in the answer. You can do it manually, by fixing it according to what coder777 said, or you can use a shortcut. Instead of checking for all cases, take upper/lowercase out of the question by transforming it to all lowercase and then checking for "nej".
Topic archived. No new replies allowed.