+ 2
Output of the code is note as expected. Can anyone help?
6 Respuestas
+ 1
Line 21, 23: you are comparing integer variable with another undefined variable
I feel you are trying to compare variable with string instead of another variable i.e
if (sex == "male")
If so, you need to change the declaration of variable from int to string at line no. 6
And finally it's not ok to declare a variable as void. A more appropriate data type here would be float as you are doing decimal point operations
Final note
Line no.6
string sex, status;
int salary;
Line 27 ,38
float tax
+ 6
1) You do not need endl for cin
2) employed is not a defined variable. You used int, so maybe employed could mean 1?
+ 6
All of them are now set at 0
+ 4
male is also not defined anywhere.
From line 27 you wrote cout >> instead of cout << as you should.
+ 2
Line 9, 13, 17: Remove endl
Endl is used after printing not after taking input
Line no. 21, 27, 38, 44: replace >> with << after cout
0
Also keep in mind that std::string's == operator is case sensitive, ie "male" != "Male". You can either use stricmp:
stricmp (sex.c_str (), "male") == 0
Or you can convert the input string to lowercase using tolower before comparing:
for (auto& c : sex) c = tolower (c);
Also of note, cin's >> operator doesn't play well with spaces. Consider using std::getline instead, like so:
cout << "Name: ";
getline (cin, Name);
cout << "Entered " << Name << endl;
Good luck <3