Help ! c++ even and odd

my prof give me this problem but i have no idea how to do it . im new to programming . sorry for my bad english :D .

this is the problem :

Create a program written in c++ language that will prompt the user to input 10 numbers . Use control structure || or Iteration Statements for inputs.The program will identify whether the input is Even od Odd . Count and compute the sum of odd and even numbers .

Hope you help me :D
thanks !!!!!!

Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main()
{
    // code goes here:

    // 1. Prompt the user to input 10 numbers
    //         (Hint: Use control structure || or Iteration Statements for inputs )

    // 2. Identify whether the input is Even or Odd
    // 3. Count
    // 4. Compute the sum of odd and even numbers

}
Last edited on
@OP, tell us how you'd solve a problem using pen and paper if this weren't a programming class, but like a philosophy class or some math logics class. Ignore the fact that your professor is telling you to iterate or use logical and/or. Forget you've even heard of the term, "c++". What would you write, like as an essay, if your professor said, "tell me how you could tell, from 10 different numbers, which ones are even and which ones are odd"?
Hint:
Use the modulus operator.
if(num % 2 == 0) //it's even, since there's no remainder when dividing by two
thanks :D :D i already finished my program :D tnks again :D :D this is my code :D :D

#include<iostream.h>
#include<conio.h>

int main(){
int a,b,c,d,e,f,g,h,i,j,even=0, odd=0 ,total_even=0, total_odd=0;

cout<<"Enter Integer : ";
cin>>a;
cout<<"Enter Integer : ";
cin>>b;
cout<<"Enter Integer : ";
cin>>c;
cout<<"Enter Integer : ";
cin>>d;
cout<<"Enter Integer : ";
cin>>e;
cout<<"Enter Integer : ";
cin>>f;
cout<<"Enter Integer : ";
cin>>g;
cout<<"Enter Integer : ";
cin>>h;
cout<<"Enter Integer : ";
cin>>i;
cout<<"Enter Integer : ";
cin>>j;
cout<<" " <<endl;

if(a%2==0
){
cout<<a<<" - is Even"<<endl;
even+=1;
total_even+=a;

}
else{
cout<<a<<" - is Odd"<<endl;
odd+=1;
total_odd+=a;
}
if(b%2==0
){
cout<<b<<" - is Even"<<endl;
even+=1;
total_even+=b;
}
else{
cout<<b<<" - is Odd"<<endl;
odd+=1;
total_odd+=b;
}
if(c%2==0
){
cout<<c<<" - is Even"<<endl;
even+=1;
total_even+=c;

}
else{
cout<<c<<" - is Odd"<<endl;
odd+=1;
total_odd+=c;
}

if(d%2==0
){
cout<<d<<" - is Even"<<endl;
even+=1;
total_even+=d;

}
else{
cout<<d<<" - is Odd"<<endl;
odd+=1;
total_odd+=d;
}

if(e%2==0
){
cout<<e<<" - is Even"<<endl;
even+=1;
total_even+=e;

}
else{
cout<<e<<" - is Odd"<<endl;
odd+=1;
total_odd+=e;
}

if(f%2==0
){
cout<<f<<" - is Even"<<endl;
even+=1;
total_even+=f;

}
else{
cout<<f<<" - is Odd"<<endl;
odd+=1;
total_odd+=f;
}

if(g%2==0
){
cout<<g<<" - is Even"<<endl;
even+=1;
total_even+=g;

}
else{
cout<<g<<" - is Odd"<<endl;
odd+=1;
total_odd+=g;
}

if(h%2==0
){
cout<<h<<" - is Even"<<endl;
even+=1;
total_even+=h;

}
else{
cout<<h<<" - is Odd"<<endl;
odd+=1;
total_odd+=h;
}

if(i%2==0
){
cout<<i<<" - is Even"<<endl;
even+=1;
total_even+=i;

}
else{
cout<<i<<" - is Odd"<<endl;
odd+=1;
total_odd+=i;
}

if(j%2==0
){
cout<<j<<" - is Even"<<endl;
even+=1;
total_even+=j;

}
else{
cout<<j<<" - is Odd"<<endl;
odd+=1;
total_odd+=j;
}

cout<<"\nEven numbers : "<<even;
cout<<"\nTotal : "<<total_even;
cout<<"\n-=-=--=-=-=-=-=-=-=-=-";
cout<<"\nOdd numbers : "<<odd;
cout<<"\nTotal : "<<total_odd;
getch();
return 0;
}
closed account (48T7M4Gy)
I only had a quick look and it looks pretty good. A couple of questions:
1. Have you tested it? Make sure your prof can work it.
2. I don't know whether you have studied arrays yet but you can simplify your code a lot especially if you combine arrays with a control loop - while, for etc. Maybe that's a refinement for the future.

Cheers and thks for getting back :)

PS I just gave it a test run. It works - well done!
Last edited on
i dont know how to use array :D just like i said im very new in programming :D
closed account (48T7M4Gy)
That's OK, I understand, save it for the (near) future.

See my PS above.
thank you :)
Topic archived. No new replies allowed.