Hello comunity,
I have to make a program which takes input two arrays (a and b) and outputs (c, c=a-b, c will containt the elements from a which are not in b).
Also each element in a and b must not repeat.
I started the sketch the code, but I'm so tired and the compiler was harsh with me, the main ideea is good I think.
What I seek is help.
If this is not a good solution then please help me find one.
Why does it give so manny errors, why is vc++ 2010 compiler so nasty, in borland when I clicked the error it pointed me to the line with the problem, can vc++ do the same?
Also it has to be modular.
Here is the code:
code.h
#ifndef code_h
#define code_h
void readArr(int,int);
void writeArr(int,int):
void difference(int,int,int,int,int);
#endif
code.cpp
#include "code.h"
#include <iostream>
using namespace std;
void readArr(int a[50],int n)
{ int i;
cout<<"size:"<<n<<endl;
cout<<"insert the elements";
for( i=1;i<=n;i++)
cout<<"a["<<i<<"]=";
cin>>a[i];
if(a[i]==a[i+1])//verify if two numbers repeat
a[i]=a[i+1];
}
void writeArr(int a[50], int n)
{
int i;
cout<<endl;
cout<<"the elements are:"<<endl;
for( i=1;i<=n;i++)
cout<<a[i]<<" ";
}
void difference(int a[50],int n,int b[50],int m, int c[50])
{
int i=0;
int j=0;
int k=0;
while((i<=n) && (j<=m))
{
if(a[i]!=b[j])
c[k]=a[i];
i++; j++; k++;
}
}
main.cpp
#include <iostream>
#include "code.h"
#include <conio.h>
using namespace std;
int main()
{
int a[50],b[50],c[50],n,m;
cout<<"a"; readArr(a,n);
cout<<"b"; readArr(b,m);
difference(a,b,c);
cout<<"elements of c are:"<<endl;
writeArr(c,n);
_getch();
return 0;
}