Breaking a while loop

Back to Programming Languages forum

DunderMifflin     2016-08-26 18:58:48
User avatar

Is it possible to break a while loop using '\n' ? eg: cin>>arr[i]; while(arr[i]!='\n') {

}

Does it work ? It does NOT show an error,niether does it work.

Quandray     2016-08-26 19:35:42
User avatar

There's nothing in what you've written that will break out of the while loop. How about

cin>>arr[i];
while(arr[i]!='\n'){


    cin>>arr[i];
}
DunderMifflin     2016-08-26 19:57:09
User avatar

It's actually the April fools problem, the input was

3(number of test case)

3 5 8

8 9 7 8

5 4

I solved this by putting a zero to separate the array, and then inputting with while(ar[i]!=0) .

I wanted to know if we can take input without the 0.

Quandray     2016-08-26 20:30:37
User avatar

After reading the number of test cases, I read a line at a time.

Now that you've solved it, you can look at how others have done it.

Quandray     2016-08-27 07:26:39
User avatar

Have a look at how Gintara_S does it.

Please login and solve 5 problems to be able to post at forum