What's wrong in this program.plz tell me

Pages: 12
Nov 21, 2012 at 10:50am
#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();
}
Nov 21, 2012 at 10:57am
#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 Nov 21, 2012 at 10:58am
Nov 21, 2012 at 11:04am
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.
Nov 21, 2012 at 11:07am
can you plz tell me how to return value
return someValue;
Nov 21, 2012 at 11:25am
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)
}
Nov 21, 2012 at 2:28pm
#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"
Nov 21, 2012 at 7:10pm
thanks alam.kindly tell me whats the purpose of namespace std;
Nov 21, 2012 at 7:16pm
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
Nov 21, 2012 at 7:27pm
cin and cout are declared from iostream.no?
Nov 21, 2012 at 7:31pm
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?
Nov 21, 2012 at 7:32pm
i am using borland 4.5
Nov 21, 2012 at 7:37pm
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.
Nov 21, 2012 at 7:40pm
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 Nov 21, 2012 at 7:43pm
Nov 21, 2012 at 9:38pm
Bloodshed Dev C++ is appallingly bad.

It's good enough for C++03 code.
Nov 21, 2012 at 9:41pm
does using namespace std: contain all libraries like math ,iomanip, string etc?
Nov 21, 2012 at 9:43pm
Well at least use the maintained version, http://orwelldevcpp.blogspot.co.uk/
Nov 21, 2012 at 9:46pm
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.
Nov 21, 2012 at 9:47pm
does it contain libraries or not?
Nov 21, 2012 at 9:52pm
It doesn't contain ANYTHING.
Nov 21, 2012 at 10:21pm
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