I am using this code that to check a set of values from a text file and show it on the output.
Code:
void MatchNumber(int b) {
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
double x1,y1,x2,y2;
while(theFile >> x1 >> y1 >> x2 >> y2 ){
rects.push_back(Rect(x1,y1, x2,y2));
}
int num=0;
int freq[101] = {0};
int adj_count = 0;
for (int x = 0; x < rects.size(); ++x) {
if (rects[b].isAdjacent(rects[x])) {
if (x==b) {
continue;
}
adj_count++;
}
}
freq[num]++;
cout<<"The common number is = "<<adj_count<<endl;
cout<< "The "<<adj_count<<" repeated = "<< freq[num]<<" times"<<endl; cout<<endl;
}
int main() {
for(int i=0; i<10; i++){
MatchNUmber(i);
}
return 0;
}
I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-
Code:
The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 4
The 4 repeated = 1 times
The common number is = 5
The 5 repeated = 1 times
The common number is = 5
The 5 repeated = 1 times
The common number is = 8
The 8 repeated = 1 times
The common number is = 9
The 9 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 8
The 8 repeated = 1 times
So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -
Code:
The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6
The common number is = 8
The 4 repeated = 1 times
The 5 repeated = 3 times
The 6 repeated = 3 times
The 8 repeated = 2 times
The 9 repeated = 1 times
How can I do that?