What's the problem with this code? Question is->Life, the Universe, and Everything

#include
void main()
{
int num;
do{
cout<<""\n\tENter the number=;
cin>>num;

	if(num!=42){
		cout<<num<<endl;
	}
}while(num!=42);

}

Do not write anything other than output.

synatax error- cout<<""\n\tENter the number=;

Do not write “Enter the number” and also instead of void main use int main and return 0 in the last…

Syntax error; it should be, #include<iostream.h> or else it wont accept any input.
and also there should be cout<<"\n Enter the number?";

There are a lot of errors which are as follows :

  1. not used using namespace std in C++ program
  2. you dont have to use cout<<“Enter a naumber” and all on codechef
  3. At the end of program you should return 0 that indicate successful
    run.

Optimizing the solution

  1. Use for loop instead of while and do-while as they are faster.

  2. Use printf and scanf even in C++ to get input and output, as they are faster than cin and cout.

Happy coding…!!

//