I'm working on my project which is a cooking assistant which instructs the user do the tasks that are stored in a binary file. I cant save the inputs into the file and read it back again. I've included my code below. Suggest me a method to do this or a correction in my code. I want to get instructions which is stored in a two dimensional array... I have to get input until the instructions and ingredients for the specific recipe is over.I'm working on c++
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<process.h>
class recipe {
int laststate, icount, qcount;
char recno;
char name[50];
float quantity[][50];
char ingredient[][50];
char instructions[][50];
char unit[5];
public:
recipe() {
//if(laststate>recno)
//recno=laststate;
//else
recno = 0;
}
void add() {
char ch;
cout << "\nEnter Recipe Name :";
cin >> name;
do {
qcount = 0;
cout << "\nQuantity, Unit and Ingredient Name :";
cin >> quantity[qcount] >> unit[qcount] >> ingredient[qcount];
qcount++;
cout << "\nDo You Want to Enter More Ingredients :";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
do {
icount = 0;
cout << "\nEnter Instructions:\n";
cin >> instructions[icount];
icount++;
cout << "\nDo You Want to Enter More Instructions :";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
recno++;
laststate = recno;
}
void display() {
cout << "Recipe Name :" << name << endl;
cout << "Ingredients :" << endl;
for (int i = 0; i <= qcount; i++)
cout << i + 1 << "." << quantity[i] << " " << unit[i] << " ";//<<ingredient[i]<<endl;
for (i = 0; i <= icount; i++)
cout << i + 1 << "." << instructions[i] << endl;
cout << "last state :" << laststate;
}
};
void main() {
clrscr();
recipe R;
char ch;
fstream file("DATA.DAT", ios::binary | ios::app);
do {
R.add();
file.write((char*)&R, sizeof(R));
cout << "DYWTC :";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
while (!file.eof()) {
file.read((char*)&R, sizeof(R));
R.display();
}
file.close();
getch();
}