What's wrong in this program.plz tell me

Pages: 12
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class converter{
private:
int x,y;
public:
int get(int);
}a;
int converter::get(int y)
{
cout<<"Please enter the height of a person in inches:";
cin>>x;
y=x/12;
return(y);
}
void main()
{
cout<<setw(55)<<"BISMILLAH HI REHMAN NI RAHIM:\n";
int b;
b=a.get(y);
cout<<b;
getch();
}
#include<iostream.h> iostream.h is non-standard and hasn't been seen since about 1998. Is is called <iostream> now. Please stop using whatever ancient compiler you are using and get something modern and correct for free.

#include<conio.h> This is non-standard and you shouldn't rely on it existing.

#include<iomanip.h> iomanip.h is non-standard and hasn't been seen since about 1998. Is is called <iomanip> now. Please stop using whatever ancient compiler you are using and get something modern and correct for free.

A modern compiler will refuse to compile your program for many reasons.

void main()
This is wrong. main returns an int. Always.

y=x/12;
This is an int divided by an int, which will give you an int. What is 14/12? One. What is 23/12? One. If you want to work with numbers that are not integers, don't use ints.

Last edited on
thanks for quick reply.can you plz tell me how to return value and how can we write parameters.should they be the same as the variables or can be different? i have been struggling to understand it for a long time but can't understand it.
can you plz tell me how to return value
return someValue;
and how can we write parameters.should they be the same as the variables or can be different? i have been struggling to understand it for a long time but can't understand it.

http://cplusplus.com/doc/tutorial/functions/
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
26
27
28
29
30
31
32

/*
 return type
  |              formal parameter i
  |                |     formal parameter f
  |                |       |                   */
double function(int i, float f)
{
    // local variables
    double d=0.1;
    const unsigned int ui = 32;

    // you can use formal parameters as if they're local variables
    d *= f + i * ui;
    return d; // return a value
}

int main()
{
    // local variables
    int a;
    float b;

/*
              function call
                  |
   local          |     actual parameter a
   variable r     |     |
       |          |     |  actual parameter b
       |          |     |  |                     */
    double r = function(a, b)
}
#include<iostream.h> is wrong
Use # include <iostream>.

You have'nt wrote using namespace std;

Well another mistake which compiler will not report but it is there in your programme its

"BISMILLAH HI REHMAN IR RAHIM:\n"

rather than
"BISMILLAH HI REHMAN NIR RAHIM:\n"
thanks alam.kindly tell me whats the purpose of namespace std;
The purpose of namespace std; is that you don't have to write std::cout or std::cin every time you want to use input or output operations. It's mostly a convenient thing
cin and cout are declared from iostream.no?
cin and cout are declared from iostream.no?


If you use an actual C++ compiler, you'll have to use namespaces. You're using some mutant, incorrect compiler from twenty years ago. Why?
i am using borland 4.5
I'm happy with Dev C++ Bloodshed. Don't know if it's best but you might wanna use it. Imo best free compilator out there.
Bloodshed Dev C++ is appallingly bad.
Borland 4.5 is indeed from twenty years ago and is even worse.

I wonder if it's possible to petition Google to lower a result in a search ranking on the grounds that it's a terrible choice.

http://www.cplusplus.com/articles/36vU7k9E/
Last edited on
Bloodshed Dev C++ is appallingly bad.

It's good enough for C++03 code.
does using namespace std: contain all libraries like math ,iomanip, string etc?
Well at least use the maintained version, http://orwelldevcpp.blogspot.co.uk/
does using namespace std: contain all libraries like math ,iomanip, string etc?

No. It just prevents you from having to write std:: in front of library elements.
does it contain libraries or not?
It doesn't contain ANYTHING.
It's good enough for C++03 code.


And a rusty nail is good enough for digging red-hot shrapnel out of your arm.
Pages: 12