Im trying to submit a successfully running code. Im able to get the output as asked. But Im getting the desired values in the output and getting an error (NZEC error) in the error box and Im not able to submit the code.
Can some one please guide me how to submit the code or tell me what the error is.
NZEC Stands for “NON ZERO EXIT CODE”, this means your program is not successfully executing.
There must be some edge cases where your program gets into some runtime trouble. I suggest you to think carefully what can cause your program to go out of bounds. Like segmentation faults maybe.
Thanks a lot Yesh. The code is giving the correct answer with out any errors. But when I’m asking to submit, a red prompt pops up saying wrong answer. Can you please tell me why.
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything.
More precisely… rewrite small numbers from input to output.
Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.
Example
Input:
1
2
88
42
99
Output:
1
2
88
SOLUTION
#!/bin/bash
for i in 1 2 88 42 99;
do
if [ $i -eq 42 ]; then
exit 0
fi
echo $i
done
Please either format your code or link to your submission - the forum software has mangled it and introduce errors!
For a start, don’t echo "Enter the number" - your output has to match the expected output precisely, and the expected output won’t include a line with Enter the number in it
Edit:
Actually, as it happens, the mangling doesn’t seem to affect things too much - removing that echo "Enter the number" will get you most of the way there, but you’ll still fail the sample testcase, but it’s hopefully obvious how to fix that
Thanks for reverting back so quickly. I just realized I made some mistakes in the code.
eg: I did not use $x instead I used x to assign value y and z to assign to the variable. And I made some changes to the code too on your recommendation.
#!/bin/bash
x=y
while [ “$x” = “y” ]
do
read n
if [ $n -ne 42 ]; then
$x=y
else
$x=z
fi
done
But still was facing the same issue. Looking into it closly, I realised that the read n function is not working as expected. Can you please tell me why would that happen. as every thing looks fine to me.
@hoody - this has actually just introduced more errors - you were closer to a solution with your previous attempt
Running this version, I now get:
>echo "5
17
5
29
42" | ./hoody-life-universe-and-everything.sh
./hoody-life-universe-and-everything.sh: line 11: y=y: command not found
./hoody-life-universe-and-everything.sh: line 11: y=y: command not found
./hoody-life-universe-and-everything.sh: line 11: y=y: command not found
./hoody-life-universe-and-everything.sh: line 11: y=y: command not found
./hoody-life-universe-and-everything.sh: line 13: y=z: command not found
./hoody-life-universe-and-everything.sh: line 10: [: -ne: unary operator expected
./hoody-life-universe-and-everything.sh: line 13: y=z: command not found
./hoody-life-universe-and-everything.sh: line 10: [: -ne: unary operator expected
./hoody-life-universe-and-everything.sh: line 13: y=z: command not found
./hoody-life-universe-and-everything.sh: line 10: [: -ne: unary operator expected
OK…I didnt know that code was supposed to read from custom input… Good lesson.
I corrected my code and submitted it and the output seems to be exactly as required. But still not able to submit the answer. Looks like my bad day. Any help on that please. …?
if you get stuck in a certain problem try looking out for solutions in “all submissions” section of the problem . and try to learn the concept from them . this is best way to start. @hoody