0
To lower case
Hi! Beginner here! So here's a sample problem... string x; cout<<"How are you?"; cin>>x; if (x=="fine") cout<<"Good!"; else cout<<"Too bad!"; So if I input fine it's output is Good! but if I capital even 1 letter in the word fine for ex. Fine it's output is Too bad!. I would like to know how I can change it so that it still output Good! even if their is a capital letter to the word fine... Thanks for those who can answer!
3 Réponses
0
Hi! Beginner here too..!! In this program.. The user will input either (FINE or Fine or fine) .... So u can use multiple if statements here.... Like.......... if(x=="fine") cout<<"good"; if (x=="FINE") cout<<"good"; if(x=="Fine") cout<<"good"; else cout<<"too bad!!! ";
0
Now if u feel that the user might input all the letters in any case... So u can convert the string into upper case N then compare it with FINE N then u can return the output as GOOD.... so for this.... We can use a function.. N run a for loop under it....
0
#include <iostream > using namespace std; void convert (string& s) { for (int i=0; i<=s.length(); i++) { s[i] = toupper (s [i] ) ; } } int main() { string s; cout<<"how are you "<<endl; getline (cin, s) ; convert (s) ; if (s==" FINE") cout<<"good..!!!! "; return 0;}............... Hope so this will help u