Taking inputs

Pages: 12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;

int main()
{
   int N;
   cout << "How many words do you want to enter:\n";
   cin >> N;
   cout << "OK; enter " << N << " words. It doesn't matter if there is more than one per line.\n";
   
   int counter = 0;
   for ( int i = 0; i < N; i++ )
   {
      string word;
      cin >> word;
      if ( word.find_first_not_of( "0123456789" ) == string::npos && stoi( word ) < 1000 ) counter++;
   }
   cout << "There are " << counter << " numbers less than 1000\n";
}


How many words do you want to enter:
7
OK; enter 7 words. It doesn't matter if there is more than one per line.
How
many
7
more
42
times
9000
There are 2 numbers less than 1000
Thanks for the help.
Topic archived. No new replies allowed.
Pages: 12