I typed this program. this program is not displaying the output

Jun 4, 2011 at 10:57am
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int x;
std::cout<<"Enter the value of x";

std::cin>>x;

std::cout<<"the value of x"<<x<<std::endl;



}
Jun 4, 2011 at 10:58am
please help me out to find out the problem.
Jun 4, 2011 at 11:10am
There's nothing wrong with the program.
Jun 4, 2011 at 11:44am
closed account (zb0S216C)
Firstly, you don't need the scope resolution operator on the standard namespace, as you already told the compiler you're using it all.

Secondly, main( ) doesn't return a numerical value.

Thridly, <stdlib.h> is a C header, not a C++ header. Instead, use the <cstdlib> header. Actually, you don't even need it in the code you posted.

Does the console shutdown immediately after execution? My guess is that it does. In that case, what you need to do is add cin.get( ) before the return statement. This will keep the console window open, until a key is pressed.

Wazzak
Last edited on Jun 4, 2011 at 11:46am
Jun 4, 2011 at 11:53am
Secondly, main( ) doesn't return a numerical value.
There's two possible interpretations for what you said, but in both cases you're wrong. Yes, it does.
Jun 4, 2011 at 12:27pm
yes my console shutdowns immediately after execution.
Jun 4, 2011 at 12:30pm
Hi everyone, Can some one tell me why exactly we use #include namespace std;
Jun 4, 2011 at 12:39pm
closed account (zb0S216C)
helios wrote:
There's two possible interpretations for what you said, but in both cases you're wrong. Yes, it does.

In the code above, main( ) doesn't return a value, even though it should. I'm not thick, I do know that main( ) returns 0 if a returning value isn't specified. So instead of being bone idle, provide a returning value.

Wazzak
Topic archived. No new replies allowed.