Write a function to have a user enter some number of integers into an array. The
ID: 3534570 • Letter: W
Question
Write a function to have a user enter some number of integers into an array. The integer values must be between -100 and +100 inclusive (+100 and -100 should be accepted as valid inputs). The integer array and the size of the array are passed into the function through parameters. Do not worry about includes. This is only a function, so there is no main routine. The function should fill the array with valid inputs. For invalid input values, inform the user of the error, but do not count that as a valid input.
Explanation / Answer
void input(int arr[],int size)
{
for(int i=0;i<size;i++)
{
cin>>a[i];
if(a[i]<-100 || a[i]>100)
{ cout <<"Invalid";
i--;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.