# Thread: Count the repeated numbers

1. ## Count the repeated numbers

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};
for (int x = 0; x < rects.size(); ++x) {

if (x==b) {
continue;
}
}
}
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?

2. Step 1 is learn how to indent code consistently.
SourceForge.net: Indentation - cpwiki
It's only 30 lines, but it's basically unreadable.

> ifstream theFile("CheckNumber.txt");
Next, you create a number of simple input files, for example
- an empty file
- a file with one rectangle
- a file with two rectangles, which "pass" the test
- a file with two rectangles, which "fail" the test

When your code passes the simple tests, then you can try it with more complicated files, knowing that you've already ironed out all the silly mistakes.

3. Originally Posted by Salem
Step 1 is learn how to indent code consistently.

> ifstream theFile("CheckNumber.txt");
Next, you create a number of simple input files, for example
- an empty file
- a file with one rectangle
- a file with two rectangles, which "pass" the test
- a file with two rectangles, which "fail" the test

When your code passes the simple tests, then you can try it with more complicated files, knowing that you've already ironed out all the silly mistakes.
I do not have problem with getting input from the file . I have already checked it. I am having problem in while calculating the total "repeated common numbers".

4. Your code still looks a mess.

You haven't provided us with an example file (short, but causes a specific problem) to test with.

If you want people to help, then minimise the amount of work they have to do (it should be just copy/paste/compile/run).

You're making people format your code and guess what's in your data file.