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"?
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.
#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.
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);
};
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