ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The program should see if you entered an odd /even or a zero and display how many of each you inputed. On the code here i dont have a loop yet.
Here is the code and the output.
#include <iostream.h>
int classifynumber (int number, int zerocount, int oddcount, int evencount);
int main () {
int zerocount;
zerocount=0;
int oddcount;
oddcount=0;
int evencount;
evencount=0;
cout<<"Enter 1 number"<<endl;
int number;
cin>>number;
int classifynumber (int number, int zeros, int odds, int evens);
cout <<"the number you entered "<< number <<" there are evecount: "<< evencount <<" oddcount " <<oddcount <<" zerocount: "<< zerocount<<endl;
return 0;
}
int classifynumber(int number, int zerocount, int oddcount, int evencount)
{
switch(number%2)
{
case 0:
evencount++;
if (number==0)
zerocount++;
break;
case 1:
case -1: oddcount++;
}
return number;
}
===================================================
Enter 1 number
3
the number you entered 3 there are evecount: 0 oddcount 0 zerocount: 0
----------------------------------------------
Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...
Based on what you provided, here is a running program.
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void classifynumber (const int number, int &zerocount, int &oddcount, int &evencount);
int main () {
int zerocount = 0;
int oddcount = 0;
int evencount = 0;
int number;
cout << "Enter a number: ";
cin >> number;
classifynumber (number, zerocount, oddcount, evencount);
cout <<"the number you entered "<< number <<" there are evencount: "<< evencount <<" oddcount " <<oddcount <<" zerocount: "<< zerocount<<endl;
return 0;
}
void classifynumber(const int number, int &zerocount, int &oddcount, int &evencount)
{
switch(number % 2)
{
case 0:
{
evencount++;
if ( number == 0)
zerocount++;
break;
}
default:
{
oddcount++;
break;
}
}
}
You continue to exhibit a pattern of seeking out old posts and replying to them without providing any useful information or questions of your own.
If you have questions of your own please post them to your own thread with proper context. Please see the Site FAQ for guidance in participation on this forum.
If this pattern continues your posting privileges may be suspended.
@theheapWalker: It is C++, so compile it with g++ But you should know that C++ is still in the experimental phase, so it keeps changing: new compilers are allowed not to compile old code, and vice versa.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.