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

C++ Array Searching Game You must use a single-dimensional array for this progra

ID: 3754921 • Letter: C

Question

C++ Array Searching Game

You must use a single-dimensional array for this program. You must write a sequential search method to search for the number requested by the user.

The following is a sample test, which must be your test case #1. You must also do test case #2 and test case #3 with a different set of data. Each test case must accept at least two lists of integers from the user, and must search at least 3 numbers for each list.

Welcome to play this wonderful number searching game!

Please enter how many integers you would like to play (up to 20, 0 to stop) >   5  

Please enter 5 integers in any order>     2   5   3   4   1

Your 5 integers are: 2 5 3 4 1

The largest integer is 5, the smallest integer is 1, the sum of all integers is 15, & the average is 3

Please enter a number to search (-1 to end the search)> 4

The number 4 is found at the position 4

Please enter a number to search (-1 to end the search)> 44

The number 44 is not found.

Please enter a number to search (-1 to end the search)> 1

The number 1 is found at the position 5

Please enter a number to search (-1 to end the search)> -1

Please enter how many integers you would like to play (up to 20, 0 to stop) >   6  

Please enter 6 integers in any order>     9   20   5   3   34   18

Your 6 integers are: 9 20 5 3 34 18

The largest integer is 34, the smallest integer is 3, the sum of all integers is 89, & the average is 14

Please enter a number to search (-1 to end the search)> 34

The number 34 is found at the position 5

Please enter a number to search (-1 to end the search)> 19

The number 19 is not found.

Please enter a number to search (-1 to end the search)> 3

The number 3 is found at the position 4

Please enter a number to search (-1 to end the search)> 20

The number 20 is found at the position 2

Please enter a number to search (-1 to end the search)> -1

Please enter how many integers you would like to play (up to 20, 0 to stop) >   -1  

Please enter how many integers you would like to play (up to 20, 0 to stop) >   -4  

Please enter how many integers you would like to play (up to 20, 0 to stop) >   0  

Thank you for playing this wonderful number searching game. Hope to see you again!

===================================================================.

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
while(1){
int n,sum=0,min=INT_MAX,max=INT_MIN,item;
cout<<"Please enter how many integers you would like to play (up to 20, 0 to stop) >";
cin>>n;
if(n==0)
break;
else if(n<0)
continue;
int arr1[n];
cout<<"Please enter "<<n<<" integers in any order> ";
for(int i=0;i<n;i++)
cin>>arr1[i];
cout<<"Your "<<n<<" integers are: ";
for(int i=0;i<n;i++)
{
cout<<arr1[i]<<" ";
sum=sum+arr1[i];
if(min>arr1[i])
min=arr1[i];
if(max<arr1[i])
max=arr1[i];
}
cout<<endl;
cout<<"The largest integer is "<<max<<", the smallest integer is "<<min<<", the sum of all integers is "<<sum<<" & the average is "<<(float)sum/(float)n;
while(1)
{
int flag=1;
cout<<endl<<"Please enter a number to search (-1 to end the search)> ";
cin>>item;
if(item==-1)
break;
for(int i=0;i<n;i++)
{
if(item==arr1[i])
{
cout<<"The number "<<item<<" is found at the position "<<i+1;
flag=0;
break;
}
else
flag=1;
}
if(flag==1)
cout<<"The number "<<item<<" is not found.";
}
}
cout<<"Thank you for playing this wonderful number searching game. Hope to see you again!";
return 0;
}