So, I want to use arrays to store my user's array, but I don't want the user to input a negative number or a number greater than 1000. How would I do this -- I'm stumped. I was thinking of using a do while loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main()
{
float array[7];
for (int x = 0; x<7 ; x++)
{
cin >> array[x];
}
// i used another for loop because I wanted to echo the array in 1 line
for (int z = 0; z<7; z++)
{
cout << array[z] << "\t";
}
if I were to try using a do while loop
1 2 3 4 5 6 7
for (int x = 0; x<7 ; x++)
{
do
{
cin >> array[x];
}while(array[x] <= 1000 && array[x] > 0);
doing this would give me funky numbers whiles still letting number greater than 1000 to go through
Smac89, could you explain to me why you used || instead of &&? || doesn't check the second condition if the first one is true. Please correct me if I'm wrong. Never mind. I'm stupid.
And keskiverto, what does the single colon mean? It's still a bit confusing for me after I read the section about it (the one on this website).
Yeah, I just got it before I check this thread again. I just read the code wrong -- It makes perfect sense now. Thanks for the help/explaination Arslan7041.
You can combine what I did with what Smac89 posted. This will let the user know (through an output message on-screen) that their input is not acceptable, as well as only output the "accepted" numbers.