Jason Jason - 2 months ago 18
C++ Question

How can I apply loop precondition i am a bit confused

I am a beginner so please bare with me.. This is my code I have to get unlimited inputs but when the difference between the two recent one's equal 15 it outputs those two numbers.

#include <iostream>
using namespace std;
int DiffCheck(int num1, int num2);

int main()
{
int input;
cout << "Enter some integers " << endl;
cin >> input;
return 0;
}
int DiffCheck(int num1, int num2)
{
int comp, difference;
do
{
while (num1 <= 15) //what to do here, I think I am supposed to put precondition here.
{
num1 = comp;
}
}
}

Answer
#include <iostream>

using namespace std;
int main()
{
   int first = 0;
   int second = 0;
   while(1)
   {
     cin>>second;

     if(second - first >= 15)
        {
            cout<<"First: "<<first<<"Second: "<<second<<endl;
            break; // stop the code once the difference is 15 or greater
        }

     first = second;
   }

  return 0;
}

Note: The user was looking for a code that will stop if the difference between the number is 15 or greater. So, changed the code.