Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My instructor has given me this code in C++ and directed me to modify it such th

ID: 3624409 • Letter: M

Question

My instructor has given me this code in C++ and directed me to modify it such that it will print out the number of times each number was entered and the array location of each number. I've got the number of times each number was entered but I can't get the array location.

Please help.

#include <iostream>
using namespace std;

int main ()
{
int i, j, numNum, num[20], uniqueNum[20], count = 0, countUnique = 0, found, indexOfUniqueNumber[20], arrayIndex = 0, flag;
cout <<"How many numbers are you going to enter? (Max 20): ";
cin >>numNum;
for(i = 0; i < numNum; i++)
{
cout <<"Please enter a number: ";
cin >>num[i];
found = 0;

for(j = 0; j < countUnique; j++)
{
if(num[i] == uniqueNum[j])//if any number in the original array is the same as any number and the unique array found will equal one
{
found = 1;
break;
}
}

if(found == 0)
{
uniqueNum[countUnique] = num[i];
countUnique++;
}
}

cout <<"Unique numbers are being printed... ";
for(i = 0; i < countUnique; i++)
{
cout << uniqueNum[i]<< " ";
cout <<" ";
}
for(i = 0; i < countUnique; i++)
{
count = 0;
for(j = 0; j < numNum; j++)
{
if(uniqueNum[i] == num[j])
count++;
indexOfUniqueNumber[i] = j;
}

cout << uniqueNum[i] << "appeared " << count <<"times at array index "<<indexOfUniqueNumber[i]<<" ";
}





system ("PAUSE");
return 0;
}

Explanation / Answer

please rate - thanks

any problems message me

#include <iostream>
using namespace std;

int main ()
{
int i, j, numNum, num[20], uniqueNum[20], count = 0, countUnique = 0, found, indexOfUniqueNumber[20], arrayIndex = 0, flag;
cout <<"How many numbers are you going to enter? (Max 20): ";
cin >>numNum;
for(i = 0; i < numNum; i++)
{
cout <<"Please enter a number: ";
cin >>num[i];
found = 0;

for(j = 0; j < countUnique; j++)
{
if(num[i] == uniqueNum[j])//if any number in the original array is the same as any number and the unique array found will equal one
{
found = 1;
break;
}
}

if(found == 0)
{
uniqueNum[countUnique] = num[i];
countUnique++;
}
}

cout <<"Unique numbers are being printed... ";
for(i = 0; i < countUnique; i++)
{
cout << uniqueNum[i]<< " ";
cout <<" ";
}
for(i = 0; i < countUnique; i++)
{
count = 0;
for(j = 0; j < numNum; j++)
{
if(uniqueNum[i] == num[j])
count++;
indexOfUniqueNumber[i] = j;
}

cout << uniqueNum[i] << " appeared " << count <<" times at array index ";
for(j = 0; j < numNum; j++)
      if(uniqueNum[i] == num[j])
          {count--;
           cout<<j;
               if( count>0)
               cout<<", ";
           else
               cout<<endl;
           }
}
system ("PAUSE");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote