one dim array - function - number of negative values

What is the wrong please?
because we have final exam at Sunday (11-1-2015)- (University of Bahrain)

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
29
30
31
32
33
34
35
36
37
38
39
40
41
// Q(5) - (25 marks)
// Write  C++ program of the following:
// 1- (sepN) is a function that accepts two parameters:
//    * an array (arr) of integer values.
//    * its (size)
//    * returns nymber of the negative values in an array (arr).
// 2- main function that:
//    * defines an array named (myArr) to store 20 integer values.
//    * promots the user to fill the array (myArr) from the keyboard.
//    * calls the function (sepN) to count the number of negative
//    values in the array (myArr)
//    * displays the number of negative values returned by function (sepN).     
// Sample Input/Output:
//        Enter 20 array elements:
//        1 2 3 4 5 6 -7 -8 -9 -10 -11 12 13 14 15 16 17 18 19 20
//        The number of negative values in array is= 5  
          
int sepN ( int arr[], int s )
{
    int n=0;
    for (int j=0; j<s; j++)
    if ( arr[j]<0 )
    ++n;
    return n;
}
         
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
   int myArr[20];
   cout<<" Enter 20 array elements:"<<endl;
   for (int i=0; i<20; i++)
   cin>> myArr[i];
   
   cout<< "The number of negative values in array is="<< sepN(myArr,20);
      
   system("PAUSE");  
   return 0;
}
Includes and "using namespace" go at the beginning of the code.

This code is ok:

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
#include <cstdlib>
#include <iostream>
using namespace std;

int sepN ( int arr[], int s )
{
  int n=0;
  for (int j=0; j<s; j++) {
    if ( arr[j]<0 )
      ++n;
  }
  return n;
}

int main()
{
 int myArr[20];
 cout<<" Enter 20 array elements:"<<endl;
 for (int i=0; i<20; i++)
   cin>> myArr[i];

 cout << "The number of negative values in array is=" << sepN(myArr,20);

 return 0;
}
Last edited on
I don't see anything REALLY wrong with this, exactly what problem are you facing?
yes yes
there is no problem

I forgot to check it

thank u very much
Topic archived. No new replies allowed.