Correct program but wrong output

i cant seem to figure out the correct way to show the same output below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #include <iostream>

using namespace std;

int main()
{
 int list[10]= {1,2,9,10,3,8,12,6,4,7}, n, countn=0, i=0;
 cout<<"Enter a number: ";
 cin>>n;
 for (i=0; i<10; i++)
 {
     cout<<list[i]<<endl;
     if (list[i]>n)
     {
         countn++;
     }
 }

 cout<<countn<<" numbers are more than "<<n<<endl;

    return 0;
}


correct output as follows:

1
2
9
10
3
8
12
6
4
7

Enter a number: 4
6 values are more than 4




your code is too efficient lol. consider this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 #include <iostream>

using namespace std;

int main()
{
 int list[10]= {1,2,9,10,3,8,12,6,4,7}, n, countn=0, i=0;

 for (i=0; i<10; i++)
 {
     cout<<list[i]<<endl;
 }
 
 cout<<"Enter a number: ";
 cin>>n;
 for (i=0; i<10; i++)
 { 
     if (list[i]>n)
     {
         countn++;
     }
 }

 cout<<countn<<" numbers are more than "<<n<<endl;

    return 0;
}
thankyou for the help
Topic archived. No new replies allowed.