I've got this assignment:
First line is the number of test (t)
Following lines are the binary strings (a)
Print out the result each on individual line
The condition
1<=t<=100
1<=length(a)<=1000
example:
Input:
2
010101
111111
Output:
010110
000000
Here's my code, the auto grader kept on telling me I got my answer wrong but I can't figure out where I got it wrong
Stop changing your code - it makes it difficult to reply to you.
You are mixing stream extraction >> with getline. The first leaves the '\n' character in the stream and the latter then picks up the remaining empty line.
Change your line cin >> t;
to cin >> t; cin.ignore( 1000, '\n' );
which will clear the newline.
Then you can put your line while( t >= 0 ) {
back to the more sensible while( t > 0 ) {
Whilst it would then appear to work there are a lot of issues with your code. Didn't your mother tell you not to pick up unnecessary global variables? - you don't know where they've been! Also, rather than setting booleans like ck to "true" or "false" you can set them directly to the result of a test.
Thank you
I changed the while condition because for some reason it only run for n-1 times with my original code
For example if I put in 3 it will only run 2 times. Maybe because I didn't clear newline as you said