hiiiii :)
i am new here i hope to get enough help to finish my simple project.
i am working on a simple program to show the union and intersection
between 2 sets. i program it the intersection is working good but the union is not working!!!
i am DIEING i try many things but
still the same problem happening " union is not working " :icon_sad: .
this is the code of my program can someone help me!! i have to finish it in 3 days:

#include<iostream.h>
int main()
 {
 int A[4],B[4],C[4],U[8];
 int i,j,k,x;
 int flag=0;
 cout<<"enter a[4]:\n";
for(i=0;i<4;i++)
cin>>A[i];

 cout<<"enter B[4]:\n";
for(i=0;i<4;i++)

cin>>B[i];
{ //start the intesection
 k=0;
 for(i=0;i<4;i++)
 for(j=0;j<4;j++)
 if(A[i]== B[j])
 {
 C[k]=A[i];
 k++;
 }
 cout<<" a intesection b is : \n";
 cout<<"{";
 for(i=0; i<k; i++)
 {
 cout<< C[i]<<" ,";

 }
 cout<<"}";
}//end the intersection

{//union
  for(x=0;x<i;i++)
  {
  U[x]=A[i];
	}


for (int i = 0; i <4; i++) {
for (int j = 0; j <8; j++) {
if (B[i] == U[j])
{
U[j] == B[i];
flag=1;
j++;
}
if (flag =! 1)
{
U[j] = B[i];
flag = 0;
}
cout << "\nUnion of Set A and Set B is ";
for (int i = 0; i <8; i++) {
cout << U[i] << " ";

}
}
}
}
return (0);
}//main

---------------------
and then i try to write a program for only union and i find a very good programe i change some values , but it not working correctly :'(

#include<iostream.h>
main()
{

int inputArraySetA[4];
int inputArraySetB[4];
int inputArrayUnion[8];
int sizeSetA = 4;
int sizeSetB = 4;
int sizeUnion = 8;
int temp = 0;
int i,j;
cout << "Input the numbers for Set A. To signify the end of the set type 0\n";
// I am using the 0 to signify the end of the set, you may want to use -1 or something similar if the set can contain 0.
for (i = 0; i < 4; i++) {
cin >> temp;
if (temp == 0) { // Change this to if (temp == -1) if using -1 to signify end of input.
break;
} else {
inputArraySetA[i] = temp;
sizeSetA++;
}
}
// This will file the first set into an array. Sets the size of the array.

cout << "Input the numbers for Set B. To signify the end of the set type 0\n";
// Again, I am using the 0 to signify the end of the set, you may want to use -1 or something similar if the set can contain 0.
for ( i = 0; i < 4; i++) {
cin >> temp;
if (temp == 0) {
break;
} else {
inputArraySetB[i] = temp;
sizeSetB++;
}
}
// This will file the second set into an array. Sets the size of the array.

// To check for duplicates, first place all of inputSetA into inputArrayUnion
for (i = 0; i < sizeSetA; i++) {
inputArrayUnion[i] = inputArraySetA[i];
}
sizeUnion = sizeSetA;
// The above assumes inputSetA does not contain any duplicates.


// Now add the elements from inputArraySetB that are not equal to inputArrayUnion (which is the same as inputArraySetA).
for ( i = 0; i < sizeSetB; i++) {
for ( j = 0; j < sizeUnion; j++) {
if (inputArraySetB[i] != inputArrayUnion[j]) {
inputArrayUnion[sizeUnion] = inputArraySetB[i];
sizeUnion++;
}
}
}

// Then to print them out.
cout << "\nUnion of Set A and Set B is ";
for (i = 0; i < 8; i++) {
cout << inputArrayUnion[i] << " ";
}
 return(0);
 }

-------------------
sOOOOOOOO
CAN SOMEONE HELP ME :?:

Proper formatting is definitely key here...

i welcome any suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.