#include <iostream>
using namespace std;

class Burger
{
private:
    double patty;
    double bun;
    double cheese;
public:
    Burger();
    double getPatty();
    double getBun();
    double getCheese();
    void setPatty(double p);
    void setBun(double b);
    void setCheese(double c);
    double hamburgerCalc(Burger b);
    double cheeseburgerCalc(Burger b);
    double dcheeseburgerCalc(Burger b);
};

double Burger::hamburgerCalc(Burger b)
{
double bun = b.getBun();
double patty = b.getPatty();
double total = bun + patty;
total = total / 2;
return total;
}

double Burger::cheeseburgerCalc(Burger b)
{
double bun = b.getBun();
double patty = b.getPatty();
double cheese = b.getCheese();
double total = bun + patty + cheese;
total = total / 2;
return total;
}

double Burger::dcheeseburgerCalc(Burger b)
{
double bun = b.getBun();
double patty = b.getPatty();
double cheese = b.getCheese();
double total = patty+patty+bun+cheese+cheese;
total = total / 2;
return total;
}


int main()
{
cout << "This is the C++ Version." << endl << endl;

Burger yum;

double patty1;
cout << "Enter the cost of each patty: ";
cin >> patty1;

yum.setPatty(patty1);

double bun1;
cout << "Enter the cost of each bun: ";
cin >> bun1;

yum.setBun(bun1);

double cheese1;
cout << "Enter the cost of each cheese slice: ";
cin >> cheese1;

yum.setBun(cheese1);

double val1 = hamburgerCalc(yum);
double val2 = cheeseburgerCalc(yum);
double val3 = dcheeseburgerCalc(yum);

cout << "A hamburger will cost: $" << val1 << endl;
cout << "A cheeseburger will cost: $" << val2 << endl; 
cout << "A double cheeseburger will cost: $" << val3 << endl;
cout << endl << "Programmer: <snip>" << endl;

}


double Burger::getPatty()
{
return patty;
}

double Burger::getBun()
{
return bun;
}

double Burger::getCheese()
{
return cheese;
}

void Burger::setPatty(double p)
{
patty = p;
}
void Burger::setBun(double b)
{
bun = b;
}
void Burger::setCheese(double c)
{
cheese = c;
}

I am trying to run this program by typing:
g++ burgerClass.cpp -o burgerClass.o
but i keep getting this:
burgerClass.cpp: In function ‘int main()’:
burgerClass.cpp:78: error: ‘hamburgerCalc’ was not declared in this scope
burgerClass.cpp:79: error: ‘cheeseburgerCalc’ was not declared in this scope
burgerClass.cpp:80: error: ‘dcheeseburgerCalc’ was not declared in this scope

Anyone know what the issue is? thanks.

Your first problem is you delcare a constructor (in your .h file) but you don't reference it in the class functions (.cpp)... So put this:

Burger::Burger()
{

}

Your other problem is the fact you don't tell the compiler where the functions are (in which class) you declare an object of "yum" so use it..

double val1 = yum.hamburgerCalc(yum);
double val2 = yum.cheeseburgerCalc(yum);
double val3 = yum.dcheeseburgerCalc(yum);

I don't understand your code. You have a main, then more class functions.. I hope this isn't all in one file.

Thank you, the problem has been solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.