char choiceA; // for main menu selection //
int choiceB; // for drink selection //
char choiceC; // for confirmation of quit selection //
float payment; // for tabulation of sales //
float salesTotal; // for storing totalsales amount //
void mainMenu(); // main menu function //
void purchaseDrinks(); // purchasing function //
void displayInventory(); // displaying inventory function //
void displaySales(); // displaying sales function //
void quitMenu(); // confirmation of quitting function //
void sellItem();
switch (choiceA)
{
case 'A':
case 'a':
purchaseDrinks();
break;
case 'B':
case 'b':
displayInventory();
break;
case 'C':
case 'c':
displaySales();
break;
case 'Q':
case 'q':
quitMenu();
break;
default:
cout << "Invalid selection." << endl;
}//end switch
mainMenu(); // back to mainMenu for invalid selection //
}
switch (choiceB)
{
case 1:
void sellItem();
break;
case 2:
cout << P01.price << endl;
cout << " Please pay in exact amount( no change will be given ): " << endl;
cin >> payment;
P01.sales = P01.sales + payment;
static int count2 = P01.invent;
--count2;
P01.inventNew = count2 ;
cout << " Item dispensed, amount left: " << count2 << endl;
break;
}
case 3:
cout << S01.price << endl;
cout << " Please pay in exact amount( no change will be given ): " << endl;
cin >> payment;
S01.sales = S01.sales + payment;
static int count3 = S01.invent;
--count3;
S01.inventNew = count3 ;
cout << " Item dispensed, amount left: " << count3 << endl;
break;
case 4:
cout << B01.price << endl;
cout << " Please pay in exact amount( no change will be given ): " << endl;
cin >> payment;
B01.sales = B01.sales + payment;
static int count4 = B01.invent;
--count4;
B01.inventNew = count4 ;
cout << " Item dispensed, amount left: " << count4 << endl;
break;
case 5:
cout << T01.price << endl;
cout << " Please pay in exact amount( no change will be given ): " << endl;
cin >> payment;
T01.sales = T01.sales + payment;
static int count5 = T01.invent;
--count5;
T01.inventNew = count5 ;
cout << " Item dispensed, amount left: " << count5 << endl;
break;
case 6:
cout << O01.price << endl;
cout << " Please pay in exact amount( no change will be given ): " << endl;
cin >> payment;
O01.sales = O01.sales + payment;
static int count6 = O01.invent;
--count6;
O01.inventNew = count6 ;
cout << " Item dispensed, amount left: " << count6 << endl;
break;
case 9:
quitMenu(); // quit selection menu //
default:
cout << "Invalid selection." << endl;
}// end of switch //
mainMenu(); // back to main menu for further purchase //
}
void sellItem()
{
if (C01.invent > 0 )
{ cout << C01.price << endl;
cout << " Please pay in exact amount( no change will be given ): " << endl;
cin >> payment;
C01.sales = C01.sales + payment; // calculation of sales total for item //
static int count1 = C01.invent; // keep count static in database //
--count1;
C01.inventNew = count1 ;
cout << " Item dispensed, amount left: " << count1 << endl;
}
else
cout << " Item is sold out. " << endl;
}
// displaying inventory of drinks //
void displayInventory()
{
cout << "No of " << C01.name << " left is: " << C01.inventNew <<endl;
cout << "No of " << P01.name << " left is: " << P01.inventNew <<endl;
cout << "No of " << S01.name << " left is: " << S01.inventNew <<endl;
cout << "No of " << B01.name << " left is: " << B01.inventNew <<endl;
cout << "No of " << T01.name << " left is: " << T01.inventNew <<endl;
cout << "No of " << O01.name << " left is: " << O01.inventNew <<endl;
The first issue, just use an if statement to check if your inventory is empty, and print that if it is, and use else for other code...
For the second issue read this thread: http://www.cplusplus.com/forum/articles/6046/
The only things that I see is that CO1.invent is never updated... you subtract 1 from a different number and change CO1.inventNew. This means when multiples of this item are purchased throughout the program the inventory number isn't actually going down... I might have missed you updating invent somenwhere else in the program though.
Also, why :
static int count1 = C01.invent;
--count1;
C01.inventNew = count1 ;
instead of just
C01.inventNew = C01.invent - 1;
I thought by using static the count will remain through out the whole program? Meaning after purchase and he go to view inventory and then make another purchase again the count will still be stored isn't it?
that is correct. static remains but in your case I don't see why you use it, why not just keep it all in the struct?
i think you should compact your code a bit, you must also see that the five cases look very similar, instead of having five cases do one function that takes the P01,C01,... as argument. Also instead of treating them individually do a vector of your structs std::vector<drinkID> mydrinks, that makes printing and calculating the sum much more compact.