>if any one knows of an easier and/or different way please let me know
An easier and different way is to just read all of the numbers and compare. At any given point it looks like you only need the current number and the previous number, and how much less the current number has to be than the previous number grows incrementally. I'm thinking of a simple loop:
#include <iostream>
using namespace std;
int main()
{
const int n = 3;
const int increment[n] = {1, 1, 2};
int prev, curr;
cin>> prev;
for (int i = 0; i < n; i++) {
cin>> curr;
if (prev - increment[i] < curr)
cerr<<"Invalid"<<endl;
prev = curr;
}
} This can be adapted to reading single digits as well, if your intention is to enter a number such as 5431 and make sure that each digit is less than the previous by a certain amount.
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401