We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,267 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Error: Not declared in scope.

#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.

2
Contributors
2
Replies
13 Hours
Discussion Span
5 Months Ago
Last Updated
3
Views
Question
Answered
danthegreat
Newbie Poster
14 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

phorce
Master Poster
738 posts since Jul 2011
Reputation Points: 63
Solved Threads: 91
Skill Endorsements: 16

Thank you, the problem has been solved.

danthegreat
Newbie Poster
14 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by phorce

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0659 seconds using 2.7MB