Hi,
I have the created the following code....
___________________________________________
#include<iostream.h>
class HotDogStand
{
private:
int HotDogsOnHand; // dogs remaining
int BunsOnHand; // buns remaining
float CashOnHand; // cash remaining
public:
void displayData() // display data
{
cout << "\n\tHot dogs on hand = "
<< HotDogsOnHand << endl;
cout << "\tBuns on hand = "
<< BunsOnHand << endl;
cout << "\tCash on hand = Lm"
<< CashOnHand << endl;
}
void initData() // get initial data from user
{
cout << "\n\tEnter dogs on hand: ";
cin >> HotDogsOnHand;
cout << "\tEnter buns on hand: ";
cin >> BunsOnHand;
cout << "\tEnter Cash on hand: ";
cin >> CashOnHand;
}
void SoldOneDog() // adjust data to reflect sale
{
--HotDogsOnHand;
--BunsOnHand;
CashOnHand = CashOnHand - 1.95;
}
}; // end of class HotDogStand
void main()
{
int stands;
cout<<"HOTDOG STAND ORGANIZER:";
cout<<"\n\nHow many stands do you own?";
cin>>stands;
HotDogStand standno[stands];
char choice = 'x';
int stand;
cout<<"\n\nPlease choose:"<<endl;
cout<<"-To initialize the data at a particular stand press 'i' "<<endl;
cout<<"-To record a sale at a particular stand press 's' "<<endl;
cout<<"-To report the current data for all the stands press 'r' "<<endl;
cout<<"-To quit the program press 'q' "<<endl;
cin>>choice;
while ( choice != 'q' )
{
if ( choice == 'i' || choice == 's' )
{
cout<<"\nPlease choose from these stands: "<<endl;
for (int j=1; j <= stands; j++)
cout<<"[ Stand "<<j<<" ]"<<endl;
cout<<"\nStand Number? ";
cin>>stand;
if (stand <= 0 || stand > stands )
continue;
}
switch (choice)
{
case 'i':
cout<<"\nInitializing the data at stand "<<stand<<"...\n";
standno[stand].initData();
break;
case 's':
cout<<"\nRecording a sale at stand "<<stand<<"...\n";
standno[stand].SoldOneDog();
break;
case 'r':
{
cout<<"\nReporting data for all the stands...\n";
for (int d=0; d<stands; d++)
{
cout<<"Data for Stand"<<stand+1<<"...\n";
standno[d].displayData();
}
break;
}
default:
cout<<"ERROR! You will return to the main menu.";
}
cout<<"\n\nPlease choose:"<<endl;
cout<<"-To initialize the data at a particular stand press 'i' "<<endl;
cout<<"-To record a sale at a particular stand press 's' "<<endl;
cout<<"-To report the current data for all the stands press 'r' "<<endl;
cout<<"-To quit the program press 'q' "<<endl;
cin>>choice;
switch (choice)
{
case 'i':
cout<<"\nYou have chosen to initialize the data at a particular stand...\n\n";
break;
case 's':
cout<<"\nYou have chosen to record a sale at a particular stand...\n\n";
break;
case 'r':
cout<<"\nYou have chosen to report the data for all the stands...\n\n";
}
}
}
______________________________________________
Try to compile it and you'll see my problem!
I'm trying to create an array of objects...
If I write: HotDogStand standno[5];
it works, however if I try to use:
HotDogStand standno[stands]; // when stands = 5
it doesn't
What may I do to fix this problem?
Thanks,
Marc