Hello guys, I have an issue with my classes, when I try to add and subtract it does not update the number of the fish I have. It runs fine until I start selling the goldfish. How would I go about it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Main.cpp
#include <iostream>
#include "FishPond.h"
usingnamespace std;
int main()
{
FishPond p;
shortint BGF = p.Buy12GoldFish();
int SGF = p.Sell10GoldFish();
cout << "You Have " << p.getGoldFish() << " GoldFish." << endl;
cout << "After Buying A Dozen Goldfish You Currently Own " << p.Buy12GoldFish() << " Goldfish." << endl;
p.setGoldFish(BGF);
cout << "After Buying A Dozen Goldfish You Currently Own " << p.Buy12GoldFish() << " Goldfish." << endl;
cout << "After Selling 10 Goldfish You Currently Own " << p.Sell10GoldFish() << " Goldfish." << endl;
return 0;
}
The value returned by the function is different, but the value of myGoldFish remains unchanged. So what do you need to do to fix that?
Why are the set functions returning values? None of the set functions are being used anywhere.
The get functions should be marked const, they don't change the state of the class. Edit: the parameters to the functions should be const as well, we make a promise not to change their value inside the function.
There is no need for the this-> in your functions, member functions have direct access to member variables.
Could the type of myGoldFish and myCatFish be changed to unsignedshortint?
Thanks everyone! sorry aha i figured it out after @Moschops gave me a hint :P. on his first comment. aha
@TheIdeasMan aha yeah my code was not complete i just wanted to find out about the issue I had :D