Question
im writing a c++ code and getting stuck on two parts. The first part, when I go to write the customer order out to the
im writing a c++ code and getting stuck on two parts. The first part, when I go to write the customer order out to the file, it writes everything but the price out right. I'll get a weird number like 5.95828e-039 or nan. When I printout to the console it works fine so not sure what's wrong. Second After I write the order out to the file, I then have to go in and read the file and calculate the sum of all the totals. Where I'm also stuck at. Here what I have so far.
enum strength {light=1, medium=2, dark=3};//enum function for strength enum coffeeName {Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4}; struct cafe { int size; int coffeeName; int strength; int sugar; float price; bool creamer = true; bool blend = true; }; struct cust { string fname; cafe rdata; int order;
}; void calcPrice(cust c) { float 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; if(c.rdata.blend != false) price = price + 0.25; if(c.rdata.creamer != false) price = price + 0.08; 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);
cout<<"Cost = $"< } int main() { cust c; struct cust arr[10]; //order number char ch1,ch2,input; //char input; int i,option, answer; int flag = 0; do //outer do-while { do //inner do-while loop { cout<<"Main Menu. "< cout<<"What coffee would you like?"<<" Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4"< cout<<"How strong? (Light=1,Medium=2,Dark=3)"< cout<<"Size of Coffee?(S=0,R=1,M=2,L=3,XL=4)"< cout<<"How much sugar?"< //writing data to file fstream order("Order.dat", ios::out|ios::app); order<<" OrderNumber:"<< c.order<<" CoffeeName:"< //if user selects No in Main Menu if(input == 'N'||input == 'n') { cout<<"[1]View an order " <<"[2] View Total Profit "; cin>>answer; switch(answer) { case 1: cout<<"Enter a order number"; cin>>option; for(i=0;i<10;i++){ //display option if(arr[10].order != option) { flag = 1; cout<<"Here is your order:"< } case 2: /*order.open("order.dat", ios::in); if(order) { //Read an item from the file getline(order, ); while(order) { cout< //prompt to reorder cout<<" Want to reorder?"< }//end of if statement for no }//outer do-while loop while((input=='y')||(input ='Y')); return 0; }//end of main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started