0

I have to write a simple beginning program that allows you to input two integers and then the program adds those two numbers and gives you the answer. The problem is my professor wants us to be more advanced and to ignore characters in one line except for integers.

As an example:

65 45
    or
78 books
56
   or
21.89
87
   or
35sk kljfdakjlf
5 jkfdal

This is my program that asks for two integers and gives the result:

  int main()
   {
        int num1, num2;

        cout << "Please give me an integer: ";
        cin >> num1;
        cout << "Please give me another integer: ";
        cin >> num2;
        cout << endl;

        cout << "The sum of " << num1 << " + " << num2 << " = " << num1 +               num2 << endl;

        system("pause");
        return 0;
   }

How do I ignore spaces in between integers, letters, periods and the space in between characters so I just get the integers?

kaya3
  • 47,440
  • 4
  • 68
  • 97
  • 3
    Why the [tag:java] tag? What does this question have to do with Java programming? Edit: tag removed. Please understand that tags are used to attract the correct experts to your question, and so great care should be taken when using them since if you use the wrong tags, you get the wrong experts, and your question either doesn't get answered or gets voted down or both. – Hovercraft Full Of Eels Sep 25 '15 at 18:04
  • 2
    C or C++? Why 2 tags? – Morlacke Sep 25 '15 at 18:08

0 Answers0