Display whole numbers if current value >= previous value

I need help with this program. I have to read and display whole numbers as long as the last input value is greater than or equal to the previous input value.
(Input: "1 2 5 4 8" Output: "1 2 5")

*I have to use a while loop

This is what I have so far. I have no clue if I'm even on the right track. Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>
#include <iomanip>
using namespace std;
int main()
{
   int cur, prev;

   cin >> prev;
   cin >> cur;
   while (cur >= prev)
   {
   cin >> prev;
   cin >> cur;
   }              
       
                              
    
    
   cout << endl; return 0; //DO NOT MODIFY, MOVE or DELETE
}
 
Think about what your code is doing.

In lines 8 and 9, you store the first number input into prev and the second number into cur.

On line 10, you say as long as cur >= prev, keep doing lines 12 and 13. Everything's OK so far.

But then on line 12, you overwrite prev with a new number input and cur with another number input. What if the 4 inputs so far were 10, 10, 0, 0. Wouldn't that mean you're saving the second 0 to cur when you're not supposed to?

Also, you need to output the numbers that were input. You should probably output the first number (stored in prev) before the loop, and then output the number in cur inside the loop, before any input operations.
Thanks for your help. I was able to figure it out and I got the program correct.
Topic archived. No new replies allowed.