Answer the question
In order to leave comments, you need to log in
Loop with check for number input C++?
You need to make an input loop, only integers, the number of attempts is up to 10.
The code below goes into an infinite loop.
int a;
int arr[10];
int i = 0;
int k = 0;
while (i < 10)
{
while (!(cin >> a))
{
cout << "Just a number";
cin.clear();
}
i++;
}
Answer the question
In order to leave comments, you need to log in
Here is the correct answer!
There is so much garbage on the Internet, when some copy-pasteers, in the hope of promoting their blog, distribute the wrong code without even testing it.
int demo_choice()
{
int a;
int i = 0;
while (!(cin >> a))
{
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
cout << "Invalid input!!! Enter number : ";
}
cout << a;
return 0;
}
You end up with an infinite number of failed attempts. The cycle is not endless. After 10 successes, it should end.
Get rid of nested loops. Use break to exit on success.
for(var i = first.length-1; i>=0; --i){
if(second.indexOf(first[i]) == -1) return false;
}
return true;
First you check the dimension, if it does not match, then they are not equal. If it matches, you need to somehow sort both the first and second array, and then compare element by element. On a vskidka something like this ...
And if an array element itself is an array, compare it too?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question