Error C2065

Hi Guys:

I am receiving error C2065. And I don't know what is happening.Could you please help me with this one. Thanks in advance.

Here is my code:

void updateAccount(PatientAccount& pt, int type)
{
if (type == 1)
{
pt.updateCharges(price1);
}
else if (type == 2)
{
pt.updateCharges(price2);
}
else if (type == 3)
{
pt.updateCharges(price3);
}
else if (type == 4)
{
pt.updateCharges(price4);
}
else
pt.updateCharges(price5);
}

The one mentioned below is the update charges function.

void PatientAccount::updateCharges(double newCharge)
{
charges +=newCharge;
}

The problem that I receive is error C2065: 'price1' : undeclared identifier.
And this repeats for price1 to price5.

How can I correct the error?

You dont need to read the code of the error at this point, read the error:

'price1' : undeclared identifier.

In your function updateAccount, there is nothing called price1. To use an object you have to declare it before. Just think: what do you mean by "price1"?
Hi chuchtanh:

Thanks for your reply. It is defined inside the class definition and the default constructor sets the default values. Look.

class Pharmacy
{
private:
double price1;
double price2;
double price3;
double price4;
double price5;
public:
Pharmacy();
~Pharmacy();
void updateAccount(PatientAccount& pt, int type);
};

How can I solve this mystery?
Thanks.
Sorry I don't see how you organize the functions. It looks like missing the "Pharmacy::" before updateAccount(...) in your previous code or you write that function right in the class (in that case the error seems to be not possible.)?
May you also post your complete code, with removing unimportant parts? Hope not so long.
Pharamacy.h

#pragma once
#include "PatientAccount.h"
class Pharmacy
{
private:
double price1;
double price2;
double price3;
double price4;
double price5;
public:
Pharmacy();//a default constructor that initialises price1 to 10.00; price2 to 20.00; price3 to 30.00; price4 to 40.00, and price5 to 50.00;
~Pharmacy(); //Deconstructor
void updateAccount(PatientAccount& pt, int type);
};

Pharmacy.cpp

# include "Pharmacy.h"
#include "PatientAccount.h"
Pharmacy::Pharmacy()
{
price1=10.00;
price2=20.00;
price3=30.00;
price4=40.00;
price5=50.00;
}
void updateAccount(PatientAccount& pt, int type)
{
if (type == 1)
{
pt.updateCharges(price1);
}
else if (type == 2)
{
pt.updateCharges(price2);
}
else if (type == 3)
{
pt.updateCharges(price3);
}
else if (type == 4)
{
pt.updateCharges(price4);
}
else
pt.updateCharges(price5);
}

PatientAccount.h

#pragma once
class PatientAccount
{
private:
int days;
double charges;
public:
//Constructor that initialises days to 0 and charges to 0.00
PatientAccount(void);
//Deconstructor
~PatientAccount(void);
//Functions
void setDays(int);
void updateCharges(double newCharge);
double getCharges() const;
};

PatientAccount.cpp

#include "PatientAccount.h"
#include <iostream>
using namespace std;
const int HospitalRate=500;
PatientAccount::PatientAccount(void)
{
days=0;
charges=0.00;
}
PatientAccount::~PatientAccount(void)
{
}
void PatientAccount::setDays(int i)
{
cout<<"How many days was the patient in the hospital?";
cin>>days;
while (days < 1)
{
cout << "Legal values are > 0. Please re-enter days at the hospital: ";
cin >> days;
}
days = i;
charges=days*HospitalRate;
}
void PatientAccount::updateCharges(double newCharge)
{
charges +=newCharge;
}
double PatientAccount::getCharges() const
{
return charges;
}

I think this might help you to give me a hand. Thanks chucthanh.
I should say I am also kind of beginner.
But did you try putting "Pharmacy::" before updateAccount?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//void updateAccount(PatientAccount& pt, int type)
void Pharmacy::updateAccount(PatientAccount& pt, int type) //Check this.
{
if (type == 1)
{
pt.updateCharges(price1);
}	
else if (type == 2)
{
pt.updateCharges(price2);
}
else if (type == 3)
{
pt.updateCharges(price3);
}
else if (type == 4)
{
pt.updateCharges(price4);
}
else
pt.updateCharges(price5);
}

After that you may encounter another issue, I don't know if it is allowed in C++ with writing void updateAccount(PatientAccount& pt, int type); in the class declaration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once
#include "PatientAccount.h"
class Pharmacy
{
private:
double price1;
double price2;
double price3;
double price4;
double price5;
public:	
Pharmacy();//a default constructor that initialises price1 to 10.00; price2 to 20.00; price3 to 30.00; price4 to 40.00, and price5 to 50.00;
~Pharmacy(); //Deconstructor
void updateAccount(PatientAccount& pt, int type);
};

Thanks for this It worked.

You made my day.

Thanks again teacher.
Last edited on
Welcome.
By the way, as you are learning programing carefully, be careful with run-time errors, or non sense errors, they are more dangerous. Please check how it runs, check the answer of the program some times, before you might make a pharmacy company break down.
Good day.
BTW do you know how can I make the program stop. I want it to display at the end
Press any key to continue...
And when I press any key it will quit.
I just want the program to stop to see the output and input given.
At the moment it is just running and closing so fast that I can't see anything.
Thanks
I work with cmd and never have to do that: check the cmd on your computer, put g++, or c++ to see if the comp. understands. If yes, better work with the cmd, compiling by "g++ myfile.cpp", and run as "a.exe". If not, you might have to use system("Pause") command before the return of the main function, like this:
http://www.gidnetwork.com/b-61.html
Topic archived. No new replies allowed.