Staying within a certain range of numbers

So i am doing some practice problems and i am not able to solve this problem. I am to ask the user for a number. The program will continue to ask the user for a number until they enter a number between 5 and 8. Once they do the program will stop and display all the numbers the user entered. This is what i have so far. The program runs but i am not getting the correct results. Where did i go wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 #include<iostream>

using namespace std;

int main()

{

int inputs;


do
{
cout<<"Enter a number "<<endl;
cin>>inputs;
}

while(inputs=>5 && inputs<=8);

cout<<inputs<<endl;


return 0;

}
I think the condition in while statement should be:
while (inputs < 5 || inputs > 8);
i.e. repeat the loop as long as "inputs" is not in the range [5, 8]
You also need to use an array/vector to store your numbers so you can print them out. At the moment, it will only display the last number as when you enter another number, the original is overwritten and thus lost.
Last edited on
Topic archived. No new replies allowed.