Hello guys,I'm kinda new in c++ and Im having a little problem. I'm trying to make a program which will count the occurrence of numbers less than 1000 in a list of numbers and words.
Any help will do.
Thanks
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
Note that if you have something like
std::ifstream fin("numbers.txt");
Each number can be extracted like:
1 2 3 4 5
int number;
fin >> number; // number will now contain the number from the file.
fin >> number; // number will now contain the second number from the file.
hint: loop
Note though that fin >> number; will fail and set fin into error state that has to be cleared before next input, if the next "word" is not a number.
A text that has some numbers somewhere is more challenging to read than a well formatted data, where you know when to expect numbers. (Although, well formatted data can still have errors.)
It gives an error which says "use of undeclared identifier 'stoi'
Time to upgrade your compiler to at least C++11.
The following would have the same effect here, as long as none of your numbers start with 0. if ( word.find_first_not_of( "0123456789" ) == string::npos && word.size() < 4 ) counter++;
Dee5 wrote:
Also the program needs to take input from a user
You can change the while loop to run off any sequence of words. Only you know how you wish to take the input from the user:
- whole line?
- multiple lines?
- sequence of words ended by a sentinel.