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

Using C++ nothing more advanced than arrays. Write a program to ask the user to

ID: 3572197 • Letter: U

Question

Using C++ nothing more advanced than arrays.

Write a program to ask the user to enter 6 numbers and store them into an integer array. Then examine the array, if the numbers in the array are all unique, display message “All unique!”, otherwise display the message “Not all unique!”.

Sample run 1:

enter a number: 1

enter a number: 87

enter a number: 3

enter a number: 19

enter a number: 56

enter a number: 777

All unique!

Sample run 2:

enter a number: 8

enter a number: 9

enter a number: 10

enter a number: 8

enter a number: 10

enter a number: 788

Not all unique!

Directions: Use the following program structure for your main. You may create more functions if you wish, but it is not required.

int main() {

int myArray[6];

// code to fill in the array from the user

// code to determine if all of the values are unique

return 0; }

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
   int myArray[6];
   for(int i=0;i<6;i++)
   {
       cout<<"enter a number:";
       cin>>myArray[i];
   }
   int kk,hat=0;
   for(int i=0;i<6;i++)
   {
       for(int j=i+1;j<6;j++)
       {
           if(myArray[i]==myArray[j])
           {
               hat=1;
               break;
           }
       }
       if(hat==1)
       {
           break;
       }
   }
   if(hat==1)
   {
       cout<<"Not all unique!"<<endl;
   }
   else
   {
       cout<<"All unique!"<<endl;
   }
   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