#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
void display()
{
clrscr();
cout<<"press: " ;

cout<<"\n 1:ADD RECORDS \n 2:RETRIEVE RECORDS \n 3:READ RECORDS \n 4:quit";
}

void main()
{
clrscr();
display();
char choice;
cout<<"\nEnter your Choice:";
cin>>choice;
switch (choice)
{
case '1':addrecords();break;
case '2':retrieve();break;
case '3':readrecords();break;
case '4':break;
default: cout<<"Only 1-4:";
}
getch();
}


void addrecords()
{
clrscr();
ofstream outfile;
outfile.open("data.dat");
if (!outfile)
{
cout<<"Error Accessing";
return ;
}
char letter[26]={"abcdefghijklmnopqrstuvwxyz"};
char number[10]={"0123456789"};
struct
{
char itemname[25];
char stocknumber[6];
int price;
int deliver;
int current;
}system;

int l=0,total=0,totalprice=0;
stocks:
cout<<"Enter stocknumber:";
cin>>system.stocknumber;

for (int i=0;i<system.stocknumber;i++)
{
if (i>=3&&i<6)
{ for (int k=1;k<=10;k++)
{if (system.stocknumber==number[k])
{ l++;
}}}

if (i<3)
{for (int j=0;j<26;j++)
{if (system.stocknumber==letter[j])
{l++;
}}}
}

if (l!=6)
{
cout<<"Invalid stocknumber\n";
l=0;
delay(500);
goto stocks;

}
cout<<"Enter itemname:";cin>>system.itemname;
cout<<"Enter current stock:";cin>>system.current;
deliver:
cout<<"Enter delivered stock:";cin>>system.deliver;
if (system.current>system.deliver)
{
total=system.current-system.deliver;
}
else
{
cout<<"OUT OF STOCKS\n";
delay(500);
goto deliver;

}
prices:
cout<<"\nPrice:";cin>>system.price;
if (system.price>0)
{
totalprice=total*system.price;
}
else
{cout<<"Invalid Price\n";
delay(500);
goto prices;
}

outfile.write((char *)&system,sizeof(system));
outfile.close();
}
void readrecords()
{
clrscr();
ifstream infile;
infile.open("data.dat");
infile.seekg(0);
while (!infile.eof())
{
infile.read((char*)&system,sizeof(system));
cout<<"\nstocknumber:"<<system.stocknumber;
cout<<"\nitemname:"<<system.itemname;
cout<<"\ncurrent stock:"<<system.current;
cout<<"\ndelivered stock:"<<system.deliver;
cout<<"\nprice:"<<system.price;
cout<<"\nTotal:"<<total;
cout<<"\ntotal price:"<<totalprice;
}
infile.close();
return;
}

void retrieve()
{
clrscr();
ifstream infile("data.txt");
if (!infile)
{
cout<<"eRROR accessing ";
return 0;
}

cout<<"\nEnter stocknumber to search:";
cin.get(stocknumber,6);

while(1)
{
infile.read(system.stocknumber,6);
if (infile.gcount()==0)
return 0;

if (strcmp(system.stocknumber,compare)==0)
{
infile.read(system.itemname,25)
readrecords();
}
infile.seekg(53,(seek_dir));
}
return;
}

pls help me to solve this program..the function didnt works well and it didnt return any value...ill tried to used a pointer but the compiler didnt accept it...thanks for replying in advance..:)

Work with that other thread which is about the same identical program. I'm not about to get involved in two different threads with the same identical problem. Its too confusing for everyone.

This article has been dead for over six months. Start a new discussion instead.