Help on filestream

This is the same cashier problem i posted but our professor included filestream problem. here's the question:

Cashier 1.0 is a C++ program that displays on the screen item codes with corresponding item description and price (at least 10 items). It asks the user to enter the code of the item purchased by a customer. It looks for a match of the code entered in the text file, items.txt. Then, its description and price are displayed on the screen too. Also, it asks for the quantity of the particular item code entered. It displays its subtotal thereafter. Moreover, it keeps on accepting item codes until ‘0’ is pressed. Consequently, it displays the total amount due. Then, it asks the user to tender the amount of cash of the customer. It displays the change and its breakdown. Finally, it sends the total amount due, amount tendered and the change to an output file, checkout.txt.

Constraints:
The program should inform the user if the file, items.txt, does not exist.
• The program should not accept item codes that are not available.
• It should not accept quantity less than or equal to 0 and must keep on asking for a valid quantity.
• It should not accept amount of cash less than the amount due and must continue asking for a valid amount.
• It should ask the user if he/she wants another transaction.


I've done everything except for the checkout.txt part and the items.txt part.

here's my code:
#include<iostream.h>
#include<conio.h>

int main()
{
int code;
int whole,a;
int thouD,fivehunD,twohunD,onehunD,fiftyD,twentyD,tenD,fiveD,oneD;
double fiftycents,twentyfivecents,tencents,fivecents;
double change,cash;
double cents;
double grapes=61.25,apples=71.50,oranges=92.50,banana=53.50,rice=54.25,pork=55.75,beef=56.50;
double eggs=57.25,milk=58.25,juice=79.50,qty,total;
double z,b,c,d,e,f,g,h,i,j;
char ans='y';

do
{
system("cls");
z=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0;
cout<<" WELCOME TO CS131xxx MART\n";
cout<<"ITEM CODES\t\tDESCRIPTION\t\tPRICE\n";
cout<<"100\t\t\tGrapes\t\t\t61.25\n";
cout<<"101\t\t\tApples\t\t\t71.50\n";
cout<<"102\t\t\tOranges\t\t\t92.50\n";
cout<<"103\t\t\tBananas\t\t\t53.50\n";
cout<<"104\t\t\tRice\t\t\t54.25\n";
cout<<"105\t\t\tPork\t\t\t55.75\n";
cout<<"106\t\t\tBeef\t\t\t56.50\n";
cout<<"107\t\t\tEggs\t\t\t57.25\n";
cout<<"108\t\t\tMilk\t\t\t58.25\n";
cout<<"109\t\t\tJuice\t\t\t79.50\n";


do{
cout<<"\nEnter Code:";
cin>>code;

if(code==100)
{m:cout<<"GRAPES\t61.25"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto m;
}
z=grapes*qty;
cout<<"Subtotal:"<<z;}
if(code==101)
{n:cout<<"APPLES\t71.50"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto n;
}
b=apples*qty;
cout<<"Subtotal:"<<b;}
if(code==102)
{o:cout<<"ORANGES\t92.50"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto o;
}
c=oranges*qty;
cout<<"Subtotal:"<<c;}
if(code==103)
{p:cout<<"BANANA\t53.50"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto p;
}
d=banana*qty;
cout<<"Subtotal:"<<d;}
if(code==104)
{q:cout<<"RICE\t54.25"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto q;
}
e=rice*qty;
cout<<"Subtotal:"<<e;}
if(code==105)
{r:cout<<"PORK\t55.75"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto r;
}
f=pork*qty;
cout<<"Subtotal:"<<f;}
if(code==106)
{s:cout<<"BEEF\t56.50"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto s;
}
g=beef*qty;
cout<<"Subtotal:"<<g;}
if(code==107)
{t:cout<<"EGGS\t57.25"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto t;
}
h=eggs*qty;
cout<<"Subtotal:"<<h;}
if(code==108)
{u:cout<<"MILK\t58.25"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto u;
}
i=milk*qty;
cout<<"Subtotal:"<<i;}
if(code==109)
{v:cout<<"JUICE\t79.50"<<endl;
cout<<"QTY:";
cin>>qty;
if(qty<=0)
{
goto v;
}
j=juice*qty;
cout<<"Subtotal:"<<j;}
if(code>0&&code<100)
{cout<<"Invalid code"<<endl;}
if(code<0||code>109)
{cout<<"Invalid code"<<endl;}
}while(code!=0);
total=z+b+c+d+e+f+g+h+i+j;
cout<<"Total:"<<total<<endl;
do{
k:cout<<"Enter cash:";
cin>>change;
if(change<total)
{
cout<<"Invalid input!"<<endl;
goto k;
}
}while(change<total);

cash=change-total;
whole=(int)cash;
cents=cash-whole;
a=cents*100+0.01;
thouD=whole/1000;
fivehunD=(whole%1000)/500;
twohunD=((whole%1000)%500)/200;
onehunD=(((whole%1000)%500)%200)/100;
fiftyD=((((whole%1000)%500)%200)%100)/50;
twentyD=(((((whole%1000)%500)%200)%100)%50)/20;
tenD=((((((whole%1000)%500)%200)%100)%50)%20)/10;
fiveD=(((((((whole%1000)%500)%200)%100)%50)%20)%10)/5;
oneD=((((((((whole%1000)%500)%200)%100)%50)%20)%10)%5)/1;
twentyfivecents=(a/25);
tencents=(a%25)/10;
fivecents=((a%25)%10)/5;

cout<<"Change:"<<cash<<"\n\n";

cout<<"=========== CHANGE BREAKDOWN ===========\n";
cout<<"1000\t\t\t"<<thouD<<endl;
cout<<"500\t\t\t"<<fivehunD<<endl;
cout<<"200\t\t\t"<<twohunD<<endl;
cout<<"100\t\t\t"<<onehunD<<endl;
cout<<"50\t\t\t"<<fiftyD<<endl;
cout<<"20\t\t\t"<<twentyD<<endl;
cout<<"10\t\t\t"<<tenD<<endl;
cout<<"5\t\t\t"<<fiveD<<endl;
cout<<"1\t\t\t"<<oneD<<endl;
cout<<"0.25\t\t\t"<<twentyfivecents<<endl;
cout<<"0.10\t\t\t"<<tencents<<endl;
cout<<"0.05\t\t\t"<<fivecents<<endl;

cout<<"Another transaction? [y/n] :";
cin>>ans;
}while(ans=='y'||ans=='Y');
cout<<"Thank you for shopping!"<<endl;
getch();
return 0;
}

HELP ON FILESTREAM PLEASE. THANK YOU
You might want to consider removing the goto statement.
Why?
Just help me with the filestream please. I need the codes
Because it becomes difficult to read and follow code that includes goto.

But you just need to
#include <fstream>

Using namespace std;
//Since you want to input a file,
ifstream file("items.txt");
//check if the file is open
if(!file.is_open())
cout<<"file not open"<<endl;

//to enter information
File>>variable;
Appreciate it. Thanks! :)
"Finally, it sends the total amount due, amount tendered and the change to an output file, checkout.txt."

how about this one?
Topic archived. No new replies allowed.