#include <iostream>
#include<iomanip>
usingnamespace std;
bool exists(int array[], int length, int newnum)
{
for (int i=0; i<length; i++)
{
if (newnum == array[i])
{
cout<<"true"<<endl;
returntrue;
}
}
returnfalse;
}
int main()
{
int count208, num208=0, countMajor, Majornum=0;
int cosc208[25];
int CTECstudents[25];
for(int index=0; index<25;index++)
{
cosc208[index]=-1;
CTECstudents[index]=1;
}
cout << "Enter the number of students who are taking COSC 208"<<endl;
cin >> count208;
for(int i=0;i<count208;i++)
{
cout << "Enter the next id of a 208 student:" <<endl;
cin >> num208;
while(exists(cosc208,count208,num208) == true)
{
cout << "Enter a unsued id of a 208 student:" <<endl;
cin >> num208;
}
cosc208[i]=num208;
for(int t=0;t<i+1;t++)
{
cout << cosc208[t]<<" ";
}
}
cout << "Enter the number of students who are majoring in CTEC"<<endl;
cin >> countMajor;
for(int i1=0;i1<countMajor;i1++)
{
cout << "Enter the next id of a CTEC major" <<endl;
cin >> Majornum;
while(exists(CTECstudents,countMajor,Majornum) == true)
{
cout <<"Enter a unsued id of a CTEC major:" <<endl;
cin >> Majornum;
}
CTECstudents[i1]=Majornum;
for(int we=0;we<i1+1;we++)
{
cout << CTECstudents[we]<<" ";
}
}
cout <<"This is the differense of the 2 arrays" << endl;
int ntCtec[50];
bool flag=false;
bool flag1=false;
int v=0;
int m=v+1;
for(int y=0; y<count208;y++)
{
ntCtec[y]=-1;
}
for(int k=0; k < count208; k ++)
{
for(int q=0; q<countMajor; q++)
{
if(cosc208[k]==CTECstudents[q])
flag=true;
}
if (flag==false)
cout<<cosc208[k]<<" ";
}
for(int p=0; p < countMajor; p ++)
{
for(int n=0; n<count208; n++)
{
if(cosc208[n]==CTECstudents[p])
flag1=true;
}
if (flag1==false)
cout<<CTECstudents[p]<<" ";
}
system("pause");
return 0;
}
this program is supposed to take imputs for to arrays and compare the arrays to see the differences and then output the arrays onto the print screen
i am having trouble with printing the differences of the two arrays if you run the program you will understand you cannot enter the same id twice in one array.