Question: I'm working on this c++ program where I'm running into an issue. The part is with the Coffee Class. It's suppose to read information from

I'm working on this c++ program where I'm running into an issue. The part is with the Coffee Class. It's suppose to read information from the structs and see if there enough product to make the order of coffee a user would order. If there is, then it displays a message that it could make the cup, if not then there not enough product. But it just skips over that part completely and I'm not sure what's going wrong. If there isn't enough product then in a switch 3 statement it would offer the user to put more product in "inventory" so the customer could try and order again.

#include #include #include #include #include #include using namespace std;

enum strength {light=1, medium=2, dark=3};//enum function for strength enum coffeeName {Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4}; //struct function struct Roostcafe { int coffeeName; double price; //for totaling price later int strength; int size; //cup size int sugar; //how many sugar bool creamer = true; bool blend = true; }; struct customer { string fname; //customer name Roostcafe rdata; int order; //get ordernumber };

//total price function void calcPrice(customer &c) { double price = 0; if(c.rdata.size == 0) price = 1.50; else if (c.rdata.size == 1) price = 2.10; else if(c.rdata.size == 2) price = 2.50; else if(c.rdata.size == 3) price = 3.00; else if (c.rdata.size == 4) price= 4.25; //for french or italian blend if(c.rdata.blend != false) price = price + 0.25; //for creamer if(c.rdata.creamer != false) price = price + 0.08; //for sugar if(c.rdata.sugar == 1) price = price + 0.13; else if(c.rdata.sugar == 2) price = price +(2*0.13); else if(c.rdata.sugar == 3) price = price + (3*0.13); c.rdata.price = price;

} class Coff{

struct productAmount { float name = 1.0; int size = 5; int sugar = 4; int creamer = 8; }; receiveOrder(customer &c){ //fetch the order calcRemainproduct(c); }

boolean calcRemainproduct(customer &c) { productAmount p; if(!p.name>=c.rdata.coffeeName) cout<<"Coffee is low"< if(!p.sugar>=c.rdata.sugar) cout<<"Sugar is low"< if(!p.creamer>=c.rdata.creamer) cout<<"Creamer is low"< if(p.name>=c.rdata.coffeeName&&p.size>=c.rdata.size&&p.sugar>=c.rdata.sugar&&p.creamer>=c.rdata.creamer) { p.name-=c.rdata.coffeeName; p.size-=c.rdata.size; p.sugar-=c.rdata.sugar; p.creamer-=c.rdata.creamer; return true; } else return false; } };

int main() { customer c; struct customer arr[10]; //order number char ch1,ch2,input; //char input; int i,option, answer; int flag = 0;

do{ //outer do-while loop do //inner do-while loop { cout<<"Main Menu. "< cout<<"Order a coffee?(Y/N) "< cin>>input; cin.ignore(); if((input == 'y')||(input == 'Y')) { cout<<"Can I have a name for the order?"< getline(cin,c.fname); //inputting a name from user

cout<<"What coffee would you like?"<<" Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4"< cin>>c.rdata.coffeeName; //customer input for order cout<<"How strong? (Light=1,Medium=2,Dark=3)"< cin>>c.rdata.strength; cout<<"Size of Coffee?(S=0,R=1,M=2,L=3,XL=4)"< cin>>c.rdata.size; cout<<"How much sugar?"< cin>>c.rdata.sugar; cout<<"Would you like French roast or Italian blend(Y/N)"< cin>>input; if(ch1=='Y') { c.rdata.blend=true; } cout<<"Do you want creamer?(Y/N)"< cin>>input; if(ch2=='Y') { c.rdata.creamer=true; } cout<<"Here is your order number #:"<<(arr[10].order + 1)<

//call to check if we have enough Coff coffobject; boolean check = true; if(check==true) cout<<"Order is ready"< else cout<<"Cannot complete the order due to low product"< if(check==true) {

//writing out to the file fstream Order("Order.dat", ios::out | ios::app); Order << "OrderNumber:" << c.order << " CoffeeName:" << c.rdata.coffeeName << " Strength" << c.rdata.strength << " Size: " << c.rdata.size << " SugarAmount: " << c.rdata.sugar << endl; calcPrice(c); Order << "Cream: " << c.rdata.creamer << " Cost: $ " << c.rdata.price << endl; Order.close(); }

} cout<<"Back to Main menu?"< cin>>input; }//inner do while loop while(input == 'Y'||input == 'y');

if(input == 'N'||input == 'n') { cout<<"[1]View an order " <<"[2] View Total Profit " <<"[3]Refill the product "; cin>>answer;

switch(answer) { case 1: cout<<"Enter a order number"; cin>>option;

for(i=0;i<10;i++){ if(arr[10].order != option) { flag = 1; cout<<"Here is your order:"< cout<<"Name:"< cout<<"Size:"< cout<<"Sugar:"< std::cout <<"Wanted French or Italian blend:"<< std::boolalpha << c.rdata.blend << ' '; //so it prints out true or false std::cout <<"Wanted Creamer:"<< std::boolalpha << c.rdata.creamer << ' '; cout<<"Cost = $" < break; }

} case 2: char filename[] = "Order.dat"; ifstream Order(filename); string line; double total_price = 0.0; double amount = 0.0; cout << "Calculating total profit"; while(getline(Order, line, ' ')) { size_t found = line.find('$'); //check line containing $ if(found !=string::npos) { stringstream ss(line.substr(1+found)); //grab the amound ss>>amount; //convert string to dollar total_price+=amount; //add the dollar to running total } } Order.close(); // print total price cout << " Total profit: " << total_price << endl; break;

//case 3: //refill product code here

}//end of switch

} //end of if statement

//prompt to reorder cout<<" Want to reorder?"< cin>>input; if((input == 'N')||(input == 'n')) { cout<<"Closing program"< exit(2); } }while((input=='y')||(input ='Y')); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!