Help with a C++ Code!🤦🏻‍♀️🤦🏻‍♀️🤦🏻‍♀️ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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
Kinshuk Vasisht
Kinshuk Vasisht - 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
Kinshuk Vasisht
Kinshuk Vasisht - 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