1 / 7
Jan 2018

#include <stdio.h>

int main(void) {
// your code here
int n;
while(1)
{
scanf("%d",&n);
if(n==42)
break;
else printf("%d",n);
}

return 0;

}

  • created

    Jan '18
  • last reply

    Oct '20
  • 6

    replies

  • 1.4k

    views

  • 4

    users

  • 1

    link

1 month later

When you run this with the sample input from the question, does your output look exactly like the sample output?

Maybe the question shouldn’t be “What is problem in my code?” but “How to test my code?”. When testing on console by “hand”, it’s hard to find difference [error]. I think that @code_071096 do it in that way, testing on console…

I think the error would be obvious even when testing on a console, as that was how I spotted it.

2 years later

Life universe and evrything(problem in my code?)
i’m a beginner btw…

int main()
{

int no;

cout<<“input number here” << no << endl;
cin >> no;

while(no != 42){
cin >> no;

if(no>100){
    break;
}

if(no == 42){
break;
}

  return;
}

Also i use c++ so which type do i have to use like there are many like c++(g++ 4.3.2) etc ?