Life, the Universe, and Everything , whats wrong with this c++ code

Hi im new to codechef and just wanted to know why this solution is not being accepted even though it gives me the correct output on codeblocks. I read the faqs and even those didnt help. Please see, thanks

#include
using namespace std;

int main()
{ int i, x[10];

for(i=0;i<4;i++)
{
        if (x[i]==42)
        break;
        else if(x[i]>=100)
        break;
            else if (x[i]<0)
            break;
        else
    cout<<x[i]<<"\n";

}

}

from where are you taking inputs?? you should use cin or scanf to take input …

3 Likes

Go to this link: getting-started (this is link for codechef getting started on the main page of codechef)

On the link above : go to Solving your first problem in C++, which contains a video.

The video should help, if you still get wrong answer, you can comment below in the comment section.



Also, read the FAQ carefully : FAQ


3 Likes

#include
using namespace std;

int main()
{ int i, x[10];
for(i=0;i<4;i++)
{cin>>x[i];}

for(i=0;i<4;i++)
{
        if (x[i]==42)
        break;
        else if(x[i]>=100)
        break;
            else if (x[i]<0)
            break;
        else
    cout<<x[i]<<"\n";

}

}
but even this is wrong

See, you are scanning only 4 numbers.It’s not mentioned that there are only 4 numbers.You need to scan upto the number scanned is 42.I think this may help you:

while(1)

{
scanf("%d",&x);

if(x==42)

{ break;

}

else

{printf("%d\n",x);

}

}

1 Like

CodeChef: Practical coding for everyone here is my code just take a look that how to take input …

Is it giving syntax error??

The questions asks you to get input from the console and you are not doing that…

1 Like

ok will do thanks :slight_smile:

you need to take the input in the code

Why are you restricting your input to 4 times while the questions ask you to stop getting input when the number entered is 42