473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

function for even and odd

i have here a code that can distinguish between odd and even numbers but my problem is how can i add for even numbers and odd numbers. here is my code...



//odd and even functions

#include <iostream.h>

void even (int a,int b,int c, int d,int e);
void odd (int a,int b, int c,int d,int e);
void addeven (int a,int b,int c,int d, int e);
void addodd (int a, int b,int c, int d,int e);

void even (int a,int b,int c,int d,int e)

{

if ((a%2)==0) cout << a << " it is even.\n";
if ((b%2)==0) cout << b << " it is even.\n";
if ((c%2)==0) cout << c << " it is even.\n";
if ((d%2)==0) cout << d << " it is even.\n";
if ((e%2)==0) cout << e << " it is even.\n";

}

void odd (int a,int b, int c,int d,int e)

{
if ((a%2)!=0) cout << a << " it is odd.\n";
if ((b%2)!=0) cout << b << " it is odd.\n";
if ((c%2)!=0) cout << c << " it is odd.\n";
if ((d%2)!=0) cout << d << " it is odd.\n";
if ((e%2)!=0) cout << e << " it is odd.\n";
}

void addeven (int a,int b,int c,int d, int e)

{
cout << "Addition for Even Numbers!" << endl;
cout << "Result: " << endl;
}

void addodd (int a, int b,int c, int d,int e)

{
cout << "Addition for Odd Numbers!" << endl;
cout << "Result: " << endl;
}

main ()

{
int a, b, c, d, e;

cout << "Enter five numbers: ";
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;

even (a,b,c,d,e);
odd (a,b,c,d,e);
addeven (a,b,c,d,e);
addodd (a,b,c,d,e);
}
May 25 '15 #1
2 2426
computerfox
276 100+
You should use <iostream> instead of <iostream.h>
You should also use an array, it's better (unless it's a school assignment...)

C++
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void validate(int* list,int evenadd,int oddadd){
  5.  for(int i=0;i<=sizeof(list);i++){
  6.   if(list[i]%2==0){
  7.    cout<<"Num"<<i+1<<"("<<list[i]<<") is even"<<endl;
  8.    cout<<list[i]<<"+"<<evenadd<<"= "<<list[i]+evenadd<<endl;
  9.   }
  10.   else if(list[i]%3==0){
  11.    cout<<"Num"<<i+1<<"("<<list[i]<<") is odd"<<endl;
  12.    cout<<list[i]<<"+"<<oddadd<<"= "<<list[i]+oddadd<<endl;
  13.   }
  14.   else{
  15.    cout<<"Num"<<i+1<<"("<<list[i]<<") is prime"<<endl;
  16.   }
  17.  }
  18. }
  19.  
  20. int main(){
  21.  int max=5;
  22.  int list[max];
  23.  
  24.  for(int i=0;i<max;i++){
  25.   cout<<"Please enter value for num"<<i+1<<": ";
  26.   cin>>list[i];
  27.  }
  28.  validate(list,1,2);
  29.  system("PAUSE");
  30.  return 0;
  31. }
  32.  
http://safe.abelgancsos.com/codepost...ect.php?id=402

C:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. void validate(int* list,int evenadd,int oddadd){
  4.  int i=0;
  5.  while(i<sizeof(list)){
  6.   if(list[i]%2==0){
  7.    printf("Num%d(%d) is even...\n",i+1,list[i]);
  8.    printf("%d + %d is: %d\n",list[i],evenadd,list[i]+evenadd);
  9.   }
  10.   else if(list[i]%3==0){
  11.    printf("Num%d(%d) is odd...\n",i+1,list[i]);
  12.    printf("%d + %d is: %d\n",list[i],oddadd,list[i]+oddadd);
  13.   }
  14.   else{
  15.    printf("Num%d(%d) is prime...\n",i+1,list[i]);
  16.   }
  17.   i++;
  18.  }
  19. }
  20.  
  21. int main(){
  22.  int max=5;
  23.  int list[max];
  24.  int i=0;
  25.  while(i<max){
  26.   printf("Please enter value for num%d: ",i+1);
  27.   scanf("%d",&list[i]);
  28.   i++;
  29.  }
  30.  validate(list,1,2);
  31.  system("PAUSE");
  32.  return 0;
  33. }
  34.  
http://safe.abelgancsos.com/codepost...ect.php?id=401

Hope that helps!
May 25 '15 #2
donbock
2,426 Expert 2GB
What do you want addeven() and addodd() to do?
Your function prototype shows that each of these functions take 5 arguments.
May 26 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
4
by: Ken | last post by:
Hello I am trying to change the color of a font in a text box. I have been reading about and trying various examples found it this group, but still can't get it right. Here is where I am...
14
by: jg | last post by:
Does C++ standard require an inline function be generated all the time ? For example, #include <iostream> using namespace std; inline int foo() {
32
by: David Mark | last post by:
I've got a collection of functions that accept a function or object (paired with a method name) as a callback. For the longest time I have relied on this test. (typeof cb == 'function') ...
0
by: Keenath | last post by:
Is it possible for an inheritor class to hide one of its parents' public functions? I don't mean just replacing the functionality, but to make it such that "Child.X()" is not a valid call, even...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
4
by: Timothy Madden | last post by:
Hello I see there is now why to truncate a file (in C or C++) and that I have to use platform-specific functions for truncating files. Anyone knows why ? I mean C/C++ evolved over many years...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.