(TCO 6) Write a function to have a user enter some number of integers into an ar
ID: 3645649 • Letter: #
Question
(TCO 6) 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 fillArray(int arr[],int size){
int num;
for(int i=0;i<size;i++){
cout<<"Enter an integer(-100 to 100): ";
cin>>num;
if(num<-100||num>100){
cout<<"An invalid number was entered and was discarded ";
i--;//decrement to avoid counting this time
}
else
arr[i]=num;
}
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.