Help me :<

Using functions and given N input numbers, perform the following tasks:

find the sum and average
find the positive, negative and zero
find the odd, even and not odd nor even(negatives)
find the sum of all positive and negative

I don't even know if I am doing right, all those with /* */ are the codes that I can't do.

Please help, thanks!


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  #include <iostream>

using namespace std;

{

int main()


int add (int a, int b) // Addition
{
    int z;
        z = (a+b);
          return z;
}

/*
int ave (int a, int b) // Average
{
    int y;
        y = (a+b);
}
*/


int sump (int a, int b) // Sum of Positives
{
    int x;
        if (a,b > 0) x = (a+b);
           return x;
}

int sumn (int a, int b) // Sum of Negatives
{
    int w;
        if (a,b < 0) w = (a+b);
           return w;
}

int  posi (int a) // Occurence of Positives
{
     int v;
         if (a>0) v++;
            return v;
            
}

int nega (int a) // Occurence of Negatives
{
    int u;
        if (a<0) u++;
           return u;
}

int zero (int a) // Occurence of Zeroes
{
    int t;
        if (a==0) t++;
           return t;
}
    
int noteo (int a) // Occurence of Not Even Nor Odd
{
    int s;
        if (a<0) s++;
           return s;
}

int even (int a) // Occurence of Even
{
    int r;
        if (a%2==0) r++;
           return r;
}

int odd (int a) // Occurence of Odd
{
    int q;
        if (a%2==!0) q++;
           return q;
}


                 

{
      
int ctr=0, unk=1;
int n;
      
      cout << "Please enter input size: ";
         cin >> n;
    
    cout << endl;
    cout << endl;
    
for (ctr=0; ctr<n; ctr++)
    
      cout << "Enter the Integer value " << (unk++) << ": ";
         cin >> a&&b

}



    cout << endl << "The sum of all integers: " << add;
    /*
    cout << endl << "The average of the sum of all integers: " << ave;
    */

    cout << endl << "Number of Positive Integer(s): " << posi;
    cout << endl << "Number of Negative Integer(s): " <<nega;
    cout << endl << "Number of Zero(es): " << zero;
    
    cout << endl;
    
    cout << endl << "Number of Odd Integer(s): " << odd;
    cout << endl << "Number of Even Integer(s): " << even;
    cout << endl << "Number of Not Even nor Odd Integer(s): " << noteo;
    
    cout << endl << "The sum of all positive integers: " << sump;
    cout << endl << "The sum of all negative integers: " << sumn;

    
    system ("pause");
    
}



*I actually get an error "8 expected `,' or `;' before '{' token" if I try to compile and run the code.
Last edited on
Just move the int main declaration from line 8 to 104.
Last edited on
Still the same error.
There's a random '{' on line 5.
Also, your 'posi', 'nega', 'zero', 'noteo', 'even' and 'odd' functions use variables which haven't been initialized.

EDIT dude you've got some serious bracket issues.
Last edited on
Even if I delete all the brackets and just leave 2 brackets to line 5 and line 127, the same issue occurs.
take out brackets at line 5 and line 86
add one at line 98
move your main function declaration to after your other function declaration
and you should be fine post edited code if you have anymore problems
Error : 90 `,' or `;' before '<<' token

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>

using namespace std;


int add (int a, int b) // Addition
{
    int z;
        z = (a+b);
          return z;
}

/*
int ave (int a, int b) // Average
{
    int y;
        y = (a+b);
}
*/


int sump (int a, int b) // Sum of Positives
{
    int x;
        if (a,b > 0) x = (a+b);
           return x;
}

int sumn (int a, int b) // Sum of Negatives
{
    int w;
        if (a,b < 0) w = (a+b);
           return w;
}

int  posi (int a) // Occurence of Positives
{
     int v;
         if (a>0) v++;
            return v;
            
}

int nega (int a) // Occurence of Negatives
{
    int u;
        if (a<0) u++;
           return u;
}

int zero (int a) // Occurence of Zeroes
{
    int t;
        if (a==0) t++;
           return t;
}
    
int noteo (int a) // Occurence of Not Even Nor Odd
{
    int s;
        if (a<0) s++;
           return s;
}

int even (int a) // Occurence of Even
{
    int r;
        if (a%2==0) r++;
           return r;
}

int odd (int a) // Occurence of Odd
{
    int q;
        if (a%2==!0) q++;
           return q;
}


                 


      
int ctr=0, unk=1;
int n;
      
      cout << "Please enter input size: ";
         cin >> n;
    
    cout << endl;
    cout << endl;
    
for (ctr=0; ctr<n; ctr++)

{
    
      cout << "Enter the Integer value " << (unk++) << ": ";
         cin >> a&&b

}

int main()


    cout << endl << "The sum of all integers: " << add;
    /*
    cout << endl << "The average of the sum of all integers: " << ave;
    */

    cout << endl << "Number of Positive Integer(s): " << posi;
    cout << endl << "Number of Negative Integer(s): " <<nega;
    cout << endl << "Number of Zero(es): " << zero;
    
    cout << endl;
    
    cout << endl << "Number of Odd Integer(s): " << odd;
    cout << endl << "Number of Even Integer(s): " << even;
    cout << endl << "Number of Not Even nor Odd Integer(s): " << noteo;
    
    cout << endl << "The sum of all positive integers: " << sump;
    cout << endl << "The sum of all negative integers: " << sumn;

    
    system ("pause");
    
}


>_<

87-100 What is that code doing at global scope?
Last edited on
Since my function is full of fallacies, I'm just going to make a new one and will just let this thread unanswered. Please close.

Thanks to everyone!
Topic archived. No new replies allowed.