Dec 13, 2017 at 9:26pm UTC
Write your question here.
I need to simply add 2 numbers. There are no syntax errors and it gives me the wrong number.
[code]
#include <iostream>
using namespace std;
class DamageNum{
public:
double CalDamout(double num1, double num2) {
Answer = num1 + num2;
}
void Damout() {
cout << Answer << endl;
}
private:
double Answer;
};
int main()
{
double num1, num2;
cout << "Enter first damage point" << endl;
cin >> num1;
cout << "enter second damage point" << endl;
cin >> num2;
DamageNum Per1;
Per1.Damout();
return 0;
}
Dec 13, 2017 at 9:41pm UTC
1 2 3
double CalDamout(double num1, double num2) {
Answer = num1 + num2;
}
This member function is expecting you to return a double. If you are only doing an assignment, change the return type to
void .
1 2
DamageNum Per1;
Per1.Damout();
You enter num1 and num2, but you never call Per1.CalDamout(). Answer is therefore never assigned a valid value.
Last edited on Dec 13, 2017 at 9:42pm UTC