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. What should I do this one is wrong!!
#include <iostream>
using namespace std;
int main()
{
int first = 0;
int second = 0;
while (1)
{
cout << "Enter some integers" << endl;
cin >> second;
if (second - first >= 15)
cout << "The difference between " << first << "and " << second << "is greater than or equal to 15." << endl;
using namespace std;
int main()
{
int first = 0;
int second = 0;
while (1)
{
cout << "Enter some integers" << endl;
cin >> second;
if (second < first)
{
swap(first, second);
}
if (second - first >= 15)
cout << "The difference between " << first << "and " << second << " is greater than or equal to 15." << endl;
#include <iostream>
#include <cstdlib>
int main()
{
std::cout << "enter some number of integers, end input with a non-numeric character:\n" ;
int first ;
std::cin >> first ; // read in the first integer
int second ;
while( std::cin >> second ) // while second is successfully read
{
if( std::abs( first-second ) > 14 ) // http://en.cppreference.com/w/cpp/numeric/math/abs
std::cout << "The difference between " << first << " and " << second << " is greater than or equal to 15.\n" ;
first = second ; // next time around the loop, first would be the current second
}
}