hi guys,
can you look at my main frunction and give me any help on how to get this program to work without copying the block of code twice (as in this code).
I have tryed to put the code into a function and then basically called it twice but the updateBill member function does not work correctly ( it does when the code is copyed ). i also thought about using a for loop, this works but I then must assume that i want to run this code x number of times.
why does it not work in a function? is it because when you call the function you are creating a new object and when it is run its course the object is out of scope and therefore unable to update?
I am using borland 5.5 on windows
Thanks for any help
Phil
can you look at my main frunction and give me any help on how to get this program to work without copying the block of code twice (as in this code).
I have tryed to put the code into a function and then basically called it twice but the updateBill member function does not work correctly ( it does when the code is copyed ). i also thought about using a for loop, this works but I then must assume that i want to run this code x number of times.
why does it not work in a function? is it because when you call the function you are creating a new object and when it is run its course the object is out of scope and therefore unable to update?
Code:
void main (void)
{
char guestName [10];
int roomNumber = 1;
float nightsStayed;
float thisRoomValue = 50;
float roomTotal = 0;
room newroom;
newroom.allocateGuest(); //this creates a dynamic object (also an aggregate of another class
newroom.accessFirstName(guestName);
cout <<"Room: "<<roomNumber<< " has been allocated to guest: "
<<guestName<<endl;
cout <<"how many nights has the guest stayed? : ";
cin >> nightsStayed;
newroom.setNoNights(nightsStayed);
newroom.setRoomCost(thisRoomValue);
roomTotal = newroom.getBillValue();
newroom.setBillValue(roomTotal);
newroom.UpdateBill(roomTotal);
newroom.deAllocateGuest();
newroom.allocateGuest();
newroom.accessFirstName(guestName);
cout <<"Room: "<<roomNumber<< " has been allocated to guest: "
<<guestName<<endl;
cout <<"how many nights has the guest stayed? : ";
cin >> nightsStayed;
newroom.setNoNights(nightsStayed);
newroom.setRoomCost(thisRoomValue);
roomTotal = newroom.getBillValue();
newroom.setBillValue(roomTotal);
newroom.UpdateBill(roomTotal);
newroom.deAllocateGuest();
getchar();
}
Thanks for any help
Phil
Comment