|
|
back to boardwhat is my problem on c++? This is my code!!! #include<iostream> #include<string> using namespace std; int main() { char s; int count = 0; while (cin >> s) { if ((s=='a')|| (s=='d')|| (s=='g')|| (s=='j')|| (s=='m')|| (s=='p')|| (s=='s')|| (s=='v')|| (s=='y')|| (s=='.')|| (s==' ')) {count+=1;} if ((s=='b')|| (s=='e')|| (s=='h')|| (s=='k')|| (s=='n')|| (s=='q')|| (s=='t')|| (s=='w')|| (s=='z')|| (s==',')) {count+=2;} if ((s=='c')|| (s=='f')|| (s=='i')|| (s=='l')|| (s=='o')|| (s=='r')|| (s=='u')|| (s=='x')|| (s=='!')) {count+=3;} } cout << count; system("pause"); return 0; } Re: what is my problem on c++? Posted by Horia 17 Sep 2017 01:40 Possibly this part (s==' ')) Re: what is my problem on c++? Posted by John 11 Jan 2022 23:11 If anyone is confused about this, note that cin ignores spaces. You should read the line as a whole with getline. string s; getline(cin, s); |
|
|