Hello, I've tried looking into this but I'm not finding a direct answer online.
I'm writing a program that will take in the users name and major. It will capitalize the first letter of every new string and it will return the value to the user. I need help with adding a statement. I'm trying to return a fun phrase only if the user enters 'computer science' or 'Computer Science.' I would like to know if I even need to include an or statement since it's being converted to upper case anyway. I tried using strcmp,but from my understanding, that is used to compare two string values. I'm not really seeing a reason I need to compare anything. Final question, is the code not working because if statements can't read multiword strings? Wait as I write this I might be getting an idea..but I'll still ask. Should I be using string compare with my declare_m variable and "computer science?" Thank you sooooo much!!
@Bob It's not much important to insert { } in every single if statement.
@SVcpp
Yes, you used C-style string so you have to use strcmp() to compare string.
Because declare_m == "Computer Science" will be always fault, if you know array is pointer that store only address, so if you use == operator, sure that the address of declare_m and "Computer Science" can't be the same.
To use lsk's idea, here's how to use the strcmp()
Instead of this
1 2 3 4
if (declare_m == "Computer Science" || declare_m == "computer science")
cout << "Your major is " << declare_m << ",fellow nerd!!!! " << endl;
else
cout << "Your major is: " << declare_m << endl;
1 2 3 4 5 6
cout << "Your major is " << declare_m; // No sense writing this twice
if (strcmp(declare_m ,"Computer Science") == 0 ) // Check if they are the same
cout << ", fellow nerd!!!! ";// And print this only IF they match
cout << endl << endl; // Add a couple newlines
return 0;
}
I appreciate it. I'm strictly doing the project the way my teacher wants it. I'm new to this and am at the point where I will just do what I'm told basically. I appreciate the help from you all.