Answer:
The c++ program for the scenario is given below.
#include <iostream>
using namespace std;
int main() {
int i,j, nZips, zipcodeList[nZips];
bool duplicates;
cout<<"This program checks if duplicate values exist in the array." <<endl;
cout<<"Enter the number of integers to be inserted in the array."<<endl;
cin>>nZips;
cout<<"Enter the integers to be inserted in the array."<<endl;
for(i=0; i<nZips; i++)
{
cin>>zipcodeList[i];
}
for(i=0; i<nZips; i++)
{
for(j=0; j<nZips; j++)
{
if(i != j)
{
if(zipcodeList[i] == zipcodeList[j])
{
duplicates = true;
cout<<"The value of duplicates variable is true meaning "<<duplicates<<endl;
break;
}
else
duplicates = false;
}
}
if(duplicates == true)
break;
}
if(duplicates == false)
cout<<"The value of duplicates variable is false meaning "<<duplicates<<endl;
return 0;
}
OUTPUT
This program checks if duplicate values exist in the array.
Enter the number of integers to be inserted in the array.
7
Enter the integers to be inserted in the array.
1234
2345
1234
5678
9087
6554
4560
3456
6789
The value of duplicates variable is true meaning 1
Explanation:
The variables mentioned in the question are used as required. There is no logic applied to validate user input. It is assumed that user inputs only valid values.
This program is designed to check whether duplicate values are present in the array. The boolean variable duplicates is assigned value true or false depending on the presence of duplicate values.
The user is prompted the number of values to be put in the array along with those values.
Once the array is filled, the array is checked for identical values. If any identical value is present, the value of duplicates variable is assigned to true and the loop is discontinued.
If no identical values are present, the loop completes and duplicates variables is assigned the value of false.
In either case, the value of the duplicates variable is displayed.