why this code show unexpected answer?


what is the wrong in this code? when i input twelve 1 then it show 66 but why?

#include <iostream>
using namespace std;
int main()
{
try
{
int arr[12];
int i, j, n, count = 0;
cout<<"Enter twelve number:"<<endl;
for(i=0; i<12; i++)
{
cin>>arr[i];
}
for(i=0; i<12; i++)
{
for(j=i+1; j<12; j++)
{
if(arr[i] == arr[j])
{
count++;
}
}
}
if(count==0)
{
throw('I');

}
cerr << "You have entered "<<count<<"duplicate numbers"<< endl;

}
catch (char I)
{
cout<<"Okay,there is no duplicate number"<<endl;
}
return 0;
}
Because 11+10+9+...+3+2+1=66
(Every entered number is 1, so they all compare equal.)

I bet it's more exciting if you enter numbers 1, 2, 3, ..., 12 instead.
Last edited on
Thanks! i get the answer. I use a break in loop & it's solved
Topic archived. No new replies allowed.