Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. "<>input; cin.ignore(); if((input == 'y')||(input == 'Y')) { cout<<"Can I have a name for the order?"<

cout<<"What coffee would you like?"<<" Columbian=1, FrenchRoast=2, ItalianBlend=3, House=4"<>c.rdata.coffeeName;

cout<<"How strong? (Light=1,Medium=2,Dark=3)"<>c.rdata.strength;

cout<<"Size of Coffee?(S=0,R=1,M=2,L=3,XL=4)"<>c.rdata.size;

cout<<"How much sugar?"<>c.rdata.sugar; cout<<"Would you like French roast or Italian blend(Y/N)"<>input; if(ch1=='Y') { c.rdata.blend=true; } cout<<"Do you want creamer?(Y/N)"<>input; if(ch2=='Y') { c.rdata.creamer=true; } cout<<"Here is your order number #:"<<(arr[10].order + 1)<

//writing data to file fstream order("Order.dat", ios::out|ios::app); order<<" OrderNumber:"<< c.order<<" CoffeeName:"<>input; } }while(input == 'Y'||input == 'y');

//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?"<>input; if((input == 'N')||(input == 'n')) { cout<<"Closing program"<

}//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

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions