+ 1
What is wrong in the code?
2 Answers
+ 2
/*first of all a and b were not declared..
and u called the sum() function in main without any arguments.. since you have declared the function with two parameters of int type.. so u need to pass argument to it..
and you have written cout<<a+b<<endl; in sayHi() function so it won't get any value and it will take garbage value in a and b and print the output..
and in the void sum(int a, int b) {} function the cout statement is as : cout<<"Result = a+b"; it will not print the value of a+b the the cout statement has everything in double quotes so it will display as it is considering it as a string..
so before moving fast on every concept first easy your hands on the basics..
*/
#include <iostream>
using namespace std;
class BankAccount {
public:
void sayHi()
{
cout << "Hi" << endl;
}
void sum(int a, int b)
{
cout<<"result= "<<a+b;
}
};
int main()
{
BankAccount test;
test.sayHi();
BankAccount add;
add.sum(5,3);
}