need help

I need help with my code.. I can't seem to analyze this problem.. need help.. thanks!! :D




#include <iostream>
using namespace std;
void displayTheUnion (char a[], char b[], char u, char i){ //this will display the union of the given letters.
int k=0, l=0;
while (k<u && l<i){
if(a[k]<b[l]) //if the first letter of set A is different from set B then display the first letter of set A
cout<<a[k++];
else if(b[l]<a[k]) //same method, display the first letter of set B and so on.
cout<<b[l++];
else{
cout<<b[l++];
k++;
}
}
while(k<u)
cout<<a[k++]; //display the other letters
while(l<i)
cout<<b[l++];
}
void displayTheIntersection (char a[], char b[], int u, int i){ //this will display the intersection of the given letters.
int k=0, l=0;
while(k<u && l<i){
if(a[k]<b[l]) // as mentioned earlier it is the same with the union part.
k++;
else if(b[l]<a[k])
l++;
else if (a[k]==b[l]){ //if the two letters are the same the program will display it.
cout<<b[l++];
k++;
}
}
}

void main()
{
char a[5], b[5];
int u= sizeof a/sizeof a[0];
int i= sizeof b/sizeof b[0];
cout<<"Enter letters for set A: ";
for(int x=0; x<5;x++){
cin>>a[x];
}

cout<<"Enter letters for set B: ";
for(int y=0;y<5; y++){
cin>>b[y];
}
cout<<"The union is: ";
displayTheUnion (a,b,u,i);
cout<<endl;
cout<<"The intersection is: ";
displayTheIntersection (a,b,u,i);
cout<<endl;
}
Please wrap code-tags around your code and make sure it is properly indented. Also what is this supposed to do and how does it fail in doing so? Only thing that I notice immediately is excessively verbose expressions such as b[l++]. Let the compiler optimize things like that and focus on making your code easy to read and understand. And yes please put some more effort into presenting your problem in general. Cheers.
What Zyl said, and you used void main(). It should be int main(). I tested this and it compiled.
Topic archived. No new replies allowed.