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);
}
2 2426
You should use <iostream> instead of <iostream.h>
You should also use an array, it's better (unless it's a school assignment...)
C++ -
#include <iostream>
-
using namespace std;
-
-
void validate(int* list,int evenadd,int oddadd){
-
for(int i=0;i<=sizeof(list);i++){
-
if(list[i]%2==0){
-
cout<<"Num"<<i+1<<"("<<list[i]<<") is even"<<endl;
-
cout<<list[i]<<"+"<<evenadd<<"= "<<list[i]+evenadd<<endl;
-
}
-
else if(list[i]%3==0){
-
cout<<"Num"<<i+1<<"("<<list[i]<<") is odd"<<endl;
-
cout<<list[i]<<"+"<<oddadd<<"= "<<list[i]+oddadd<<endl;
-
}
-
else{
-
cout<<"Num"<<i+1<<"("<<list[i]<<") is prime"<<endl;
-
}
-
}
-
}
-
-
int main(){
-
int max=5;
-
int list[max];
-
-
for(int i=0;i<max;i++){
-
cout<<"Please enter value for num"<<i+1<<": ";
-
cin>>list[i];
-
}
-
validate(list,1,2);
-
system("PAUSE");
-
return 0;
-
}
-
http://safe.abelgancsos.com/codepost...ect.php?id=402
C: -
#include <stdio.h>
-
-
void validate(int* list,int evenadd,int oddadd){
-
int i=0;
-
while(i<sizeof(list)){
-
if(list[i]%2==0){
-
printf("Num%d(%d) is even...\n",i+1,list[i]);
-
printf("%d + %d is: %d\n",list[i],evenadd,list[i]+evenadd);
-
}
-
else if(list[i]%3==0){
-
printf("Num%d(%d) is odd...\n",i+1,list[i]);
-
printf("%d + %d is: %d\n",list[i],oddadd,list[i]+oddadd);
-
}
-
else{
-
printf("Num%d(%d) is prime...\n",i+1,list[i]);
-
}
-
i++;
-
}
-
}
-
-
int main(){
-
int max=5;
-
int list[max];
-
int i=0;
-
while(i<max){
-
printf("Please enter value for num%d: ",i+1);
-
scanf("%d",&list[i]);
-
i++;
-
}
-
validate(list,1,2);
-
system("PAUSE");
-
return 0;
-
}
-
http://safe.abelgancsos.com/codepost...ect.php?id=401
Hope that helps!
What do you want addeven() and addodd() to do?
Your function prototype shows that each of these functions take 5 arguments.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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 ]
|
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...
|
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()
{
|
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')
...
|
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...
|
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...
|
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....
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |