0

Help with a C++ Code!🤦🏻‍♀️🤦🏻‍♀️🤦🏻‍♀️

Hi I want to write a code for a program which reads the text,and counts the number of words and numbers . Example: Hello,Can i borrow 200 Dollars? Answer: 6 words

17th Aug 2018, 5:58 AM
Fateme
3 Réponses
+ 1
Fateme Can you tell me where did you run the code? On sololearn or on a PC? If it was a PC, did you enable the C++11 flag for your compiler?
17th Aug 2018, 6:31 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
Do you consider 200 a word in this case? If yes, for simple cases just use count_if() from <algorithm> like this : string text; // Your text. int num_of_words = 1+count_if(text.begin(),text.end(),[](char c){return c==','||c==' ';}); Here is more information on how to use this function : www.cplusplus.com/reference/algorithm/count_if Also try using this sample code : https://code.sololearn.com/cJ0ZYKucNE94/?ref=app
17th Aug 2018, 6:07 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
Thank u very much and yes i am considering each number in the text as a word ! and unforunately i could not use the code u wrote😞😞😞
17th Aug 2018, 6:30 AM
Fateme