Hello all, like always : D
I'm working on a structure program that has an array (m) that asks the user to enter its values, and then it transfers the even numbers to an array (even) and the odd to another (odd). Both (evan) and (odd) arays are in a structure (x) ; plus, I have made another structure (y) that is connected to (x) and has it same attributes.
My problem is, that after I run the program and add the numbers, I don't get the values in the (odd) and (even) arrays ; but instead I get their memory addresses I guess!
The code is:
#include<iostream.h>
#include <stdio.h>
#include <conio.h>
struct x
{
int even[20];
int odd[20];
int countEven;
int countOdd;
};
main()
{
int m[20],i,sum=0;
struct x y;
y.countEven = 0;
y.countOdd = 0;
for (i=0;i<20;i++)
{
printf("\n Enter No.[%d] = ",i);
scanf("%d",&m[i]);
sum+=m[i];
if (m[i] % 2 == 0)
y.even [y.countEven++]=m[i];
else
y.odd [y.countOdd++]=m[i];
}
cout<<"Even numbers are:"<<y.even<<endl;
cout<<"Odd numbers are:"<<y.odd<<endl;
return ( 0 ) ;
}
Plus in the (cout) area at the end of the program, I wanna add more cool things that displays higher/lower numbers in both arrays, and also the total count/sum of both arrays, so the program will display these things after adding the values by the user:
- Even numbers are: ------------
- Odd numbers are: -------------
- Higher even number: ---------
- Lower even number: ----------
- Higher odd number: -----------
- Lower odd number: -----------
- The sum of even numbers: -------
- The sum of odd numbers: --------