Question
C++ Use what you learned about array reversal loops in the preceding exercise. Prompt the user to enter a list of up to 20 integers,
C++ Use what you learned about array reversal loops in the preceding exercise. Prompt the user to enter a list of up to 20 integers, and a non-numeric to quit. In a loop, read the inputs into an array you've already declared of length 20. Hint: you can detect the non-numeric has been entered, while reading in the values, using:
int number[20], i=0; while (cin >> number[i] && i < 20) //cin returns false if invalid entry (non-numeric) { i++; }
Print out the array, all elements on one line, terminated with a newline. Reverse the array by swapping elements. Re-print the array reversed.
Assuming the user will enter "1 2 3 4 5 q", your code should print: "Enter a list of up to 20 integers, and a non-numeric to quit: " "The original array is: 1 2 3 4 5" "The reversed array: 5 4 3 2 1"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started