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.
#include <iostream>
usingnamespace 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.
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
#include <iostream>
usingnamespace 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");
}