problem in a program
Mar 31, 2009 at 7:37pm UTC
I have made a simple program using classes but It is not running . Can anyone please tell me what is wrong with it.
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
#include<iostream>
using namespace std;
class wasim {
int x;
int y;
public :
int function(int a,int b);
void printmessege();
double addition(int a,int b);
};
int wasim::function(int a,int b)
{x=a+b;
return x;
}
void wasim::printmessege()
{
cout<<"this is string" ;
}
double wasim::addition (int a ,int b)
{ return (a-b);
}
int main()
{
wasim tukhi;
wasim masih;
wasim bot;
tukhi.function(4,5);
masih.printmessege();
bot.addition(7,8);
cout<<tukhi.function(4,5)<<" " <<masih.printmessege<<" " <<bot.addition(7,8);
return 0;
}
Mar 31, 2009 at 7:51pm UTC
other than "addition()" actually performing subtraction, I don't see anything wrong with it.
What do you mean by "not running"? I suspect it
really is running and is just closing right away. See the sticky thread here:
http://cplusplus.com/forum/beginner/1988/
Mar 31, 2009 at 7:58pm UTC
the
printmessege function has a void return type, but you try to output it anyway. Also, you didn't include the parameter brackets. Line 30 should be replaced with:
1 2 3
cout<<tukhi.function(4,5)<<" " ;
masih.printmessege();
cout<<" " <<bot.addition(7,8);
Mar 31, 2009 at 8:00pm UTC
Thank you jdd !
you cleared my concepts !
Topic archived. No new replies allowed.