Code:
#include <iostream>
using namespace std;
#include <string>
class IceCreamCone
{
private:
string flavor;
int numOfScoops;
string typeOfCone;
float price;
public:
IceCreamCone(string = "Vanilla", int = 1 , string = "Sugar");
void setPrice();
float getPrice();
};
void IceCreamCone::setPrice()
{
price = 0;
}
float IceCreamCone::getPrice()
{
return price;
}
IceCreamCone::IceCreamCone(string flvr, int numScoops , string typeCone )
{
setPrice();
price = 0.75 * (float)numOfScoops;
if( typeCone == "waffle")
price += 0.40;
}
int main(void)
{
IceCreamCone iceCream;
IceCreamCone iceCreamTwo("chocolate", 3 , "waffle" );
cout << iceCream.getPrice() << endl;
cout << iceCreamTwo.getPrice() << endl; // prints "garbage"
return 0;
}
In the main function after calling function getPrice() (line 39) for the object iceCreamTwo it ends up printing garbage,
Code:
cout << iceCreamTwo.getPrice() << endl;
and I am not quite sure why it happens, since program prints good number for iceCream object.