Question
C++ program; i need 7.14 as well please.
7.13 (Duplicate Elimination with arrayUse a one-dimensional array to solve the following problem. Read in 20 numbers, each of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;

const int size = 20; //constant variable size that we will used as the size of our array as it is mentioned in question that we have to take 20 numbers so size is 20;
void main()
{
   int arr[size]; //declaring our array of size=20

   for (int i = 0; i < size; i++) //this loop will iterate for size =20 times to take input from user
   {
       system("cls"); //this is just for clearing anything written on console
       cout << "Enter No. " << i + 1 << ":" << endl;

       cin >> arr[i]; //taking input from user

       if (arr[i] < 10 || arr[i]>100) //here our first checking is done , if the number>100 or smaller than 10 then it willl be rejected
       {
           cout << "Number Out of Bound!!! Please enter that no again." << endl; //error message
           i = i - 1; //as the wrong no was entered at i th position so we reset i to the previous position in order to get correct no at same position
           system("pause");
       }
       for (int j = 0; j < i; j++) //here our second checking starts, if the no is doplicate ,it would be rejected. Here in this loop , I took j<i. This is very simple.Suppose
                                       //we have entered 10 numbers yet, so i=9 as index starts from 0. So j<i means we have to check only 10 indexes as only those are filled and rest of the array is empty.

       {
           if (arr[i] == arr[j]) // if newly entered no i.e arr[i] matches arr[j] which could be any previously stored number then it will be rejected.
           {
               cout << "Duplicate Detected!!! Please enter that no again." << endl; //error message
                 
               i = i - 1; //as the wrong no was entered at i th position so we reset i to the previous position in order to get correct no at same position
               system("pause");
               break; // as duplicate is found so no need to loop again so we break the loop.
              
           }
       }
   }

   system("cls");

   cout << "Numbers Entered By The User are:" << endl;
   for (int i = 0; i < size; i++) //displaying the array.
   {
       cout << arr[i] << " ";
   }
   system("pause");
}

c\users\haris sheikh\documents visual studio 2013\Projects\dup_array\Debug Enter No. 4: 444 Number Out of Bound!!! Please ent

c:\users\haris sheikh\documents visual studio 2013\Projects\dup_array\Debug\dup_array.exe Enter No. 4: 11 Duplicate Detected!

- O X O c:\users\haris sheikh\documents\visual studio 2013\Projects dup_array\Debug\dup_array.exe Numbers Entered By The User

COMMENT DOWN FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
C++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help with this C++ problem using Array Use a one-dimensional array to solve the following...

    Please help with this C++ problem using Array Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100. As each number is read validate it and store it in the array. After reading all the values, display only the unique values that the user entered. Make sure you account for the worst case scenario in which all 20 numbers are different. Use the smallest possible array to solve this...

  • Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

    Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...

  • ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

    ll this is a java code do it in eclipse please. thank you. Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs...

  • Write a console application in c# that uses a one dimensional array; prompt the user to...

    Write a console application in c# that uses a one dimensional array; prompt the user to enter letters, ( a, b, c, … z). As each letter is input, store it in the array only if it is not a duplicate of previous letters entered. After 7 unique letters have been entered, display the unique values in the array. Be sure to test with duplicate values.

  • Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load...

    Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load them into an array. Add up all the values and store the answer in a variable. Find the largest and smallest number in the array. Put each into its own variable. Print to the screen the sum, largest value, and smallest value. Copy the array to a second array in reverse order. Print out the second array. Read in 20 integer numbers, all in...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

  • I'm really stuck I need help. C++ Draw separate flowcharts to solve each of the following...

    I'm really stuck I need help. C++ Draw separate flowcharts to solve each of the following problems: Read in 20 numbers and write out how many of them were positive (write out the count, not the actual input numbers). Read in numbers until the user chooses to quit. Write out the smallest of the input values. (Make it so that the user has to enter at least one value) Read in numbers until 10 positive values have been found. Write...

  • I need help in C++ assignment. please add statements and i am Xcode complier user. Requested...

    I need help in C++ assignment. please add statements and i am Xcode complier user. Requested files: CountDecades.cpp (Download) Maximum upload file size: 96 KiB Write a C++ program named CountDecades.cpp. In this program you will have two integer arrays. One named inputArray of size 20 containing the values: 83, 2, 23, 11, 97, 23, 41, 67, 16, 25, 1 , 4, 75, 92, 52, 6, 44, 81, 8, 64 in the order specified, and an empty integer array of...

  • Hello. I am using a Java program, which is console-baed. Here is my question. Thank you....

    Hello. I am using a Java program, which is console-baed. Here is my question. Thank you. 1-1 Write a Java program, using appropriate methods and parameter passing, that obtains from the user the following items: a person’s age, the person’s gender (male or female), the person’s email address, and the person’s annual salary. The program should continue obtaining these details for as many people as the user wishes. As the data is obtained from the user validate the age to...

  • COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning...

    COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning Outcome #2: Create and utilize arrays to store lists of related data Programming Problem You have been hired to create a C++ program to simulate the lottery. Your program allows users to see how often their lottery number choices match a randomly generated set of numbers used to pick lottery winners. The company, "How Lucky Are You?, Inc." wants a modular, professional and user-friendly...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT