The first adjacency problem is driving me nuts, I think I've been looking at it for too long:
my code:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile1("data1");
ofstream outFile2("data1-CONS");
int x, xPrev, consCount=0;
// bool firstTime = true;
inFile1>>xPrev;
outFile2<<xPrev<<" <<== This is Xprev"<<endl;
inFile1>>x;
outFile2<<x<<" <<== This is X in first read in"<<endl<<endl;
while (!inFile1.fail()){
if (xPrev>=0 || x>=0){
if (x==xPrev)
consCount++;
} else
outFile2<<consCount<<"<<== # of CONS DUPS"<<endl;
xPrev=x;
inFile1>>x;
}
outFile2<<"THERE ARE "<<consCount<<" consecutive duplicates"<<endl;
cout<<"hold on to ya butts"<<endl;
return 0;
}
INFILE::
data1:
4 4 4 3 2 2 4 3 2 4 5 6 7 8 -9
2 3 4 4 4 0
One: the code is not exiting once it hits a negative number , I'm a little confused as to where to put that condition,
Two: the number of consecutive duplicates should be 2, but i'm getting 3 (this is before I added the extra numbers after the -9... with the numbers after -9, I get 5 consecutive duplicates)
any advice? Thanks
SZ