problem in pgm

i have written a program to input two no from the keyboard and display the larger value on screen...the pgm code is...



#include<iostream.h>
#include<conio.h>

int main()
{
clrscr();
int a,b;
cout<<"enter first number:";
cin>>a;
cout<<"\nenter second number:";
cin>>b;
if(a>b)
{
cout<<"\The greater number is:"<<a;
}
else
{
cout<<"the greater number is:"<<b;
}
getch();
return 0;
}


BUT THE OUTPUT IS NOT COMING....SOMEONE PLS HELP ME OUT...I SAHLL BE VERY THANKFUL
Is this exactly how you have your program?

Remove the ".h" from iostream.h #include <iostream>

Also after the include's use using namespace std;

Last at cout<<"\The greater number is:"<<a; You forgot the 'n' after '\'.
Last edited on
Charuzen, try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream.h>
#include<conio.h>

int main()
{
int x, y;

clrscr();

cout<<"Enter two numbers separated by a space:";
cout<<endl;
cin>>x;
cout<<endl;
cin>>y;
cout<<"The larger number is: ";

{
if (x>y)
cout<<x;
else
cout<<y;
}

getch();
}


Last edited on
Charuzen, try this

What is the difference between what charuzen posted and what you posted? Except that you change the variables to x and y and you prompt the user to enter the two numbers in a single line?

You still didn't correct the #include <iostream.h> and you still don't use using namespace std;
cout, cin and endl are part of the namespace std... If you want to use them you have to use a namespace notation:
http://www.cplusplus.com/doc/tutorial/namespaces.html
1
2
3
using namespace std;
using std::cout;
std::cout << "out";


And clrscr() is not part of c++ STL. It works only with Borland C++.
What is the difference between what charuzen posted and what you posted? Except that you change the variables to x and y and you prompt the user to enter the two numbers in a single line?


OoOoPs! dang it!
didn't notice....

btw, #include<iostream.h> is used in old compilers,
well, i think he's using one so i thought it didnt made any problems.., plus, in that old compiler, using
1
2
3
using namespace std;
using std::cout;
std::cout << "out";
does not work...


anyway, just choose between getch(); and
return 0;....
Last edited on
getch(); and return 0; are two completly different things...

getch(); Is used to catch a keystroke from the user.

return 0; Is the return of a function, or in this case the return of the main which terminates the program.

You can have them both. In this example you just use one to make your program wait for a keystrike and the other to make your program end and return to its caller the value 0.
Topic archived. No new replies allowed.