basicly my project is making a shopping list which allow the user to:
- type 1 to add a new shopping list
- type 2 to add an item on existing shopping list
- type 3 to check certain items in a certain list as bought
- type 4 to display a shopping list on certain date
- type 5 to exit
i made some research and i learned how to put every list the user enter into a file but i don't know how to display the lists names and let the user choose a certain list to add to it a new item
that's what i have so far
#include <iostream>
#include <string>
#include <fstream> //item name, quantity for each item, checked, date to buy the list, name of store
using namespace std;
void makelist();
void addtolist();
void checkitem(); // still don't know how to write it
void displaylist(); // still don't know how to write it
struct list
{
int quant;
string items;
string place;
string date;
};
int main()
{
int a;
cout << " *Welcome to your shopping list*" << endl;
cout << "please enter: " << endl;
do
{
cout << " (1) If you want to make a list." << endl;
cout << " (2) If you want to add an item to an existing list." << endl;
cout << " (3) If you want to check a certain item as bought" << endl;
cout << " (4) If you want to diplay a certaina shopping list in a certain date" << endl;
cout << " (5) If you want to exit" << endl;
cin >> a;
switch (a)
{
case 1:
makelist();
break;
case 2:
addtolist();
break;
/*case 3:
checkitem();
break;
case 4:
displaylist();
break;
*/case 5:
cout << "...CLOSING...";
return 0;
default:
cout << "..ERROR..plz enter numbers from 1 to 5";
break;
}
} while (a != 5);
return 0;
}
void makelist()
{
string FileName;
cout << "enter the list name: ";
cin >> FileName;
ofstream WriteToFile;
WriteToFile.open(FileName);
list L;
int n;
cout << "Enter number of items:" << endl;
cin >> n;
for (int i = 0; i <= n; i++)
{
cout << "Enter items and quantity:" << endl;
cin >> L.items >> L.quant;
WriteToFile << L.items << L.quant;
}
cout << "Enter the store's name:" << endl;
cin >> L.place;
WriteToFile << L.place;
cout << "Enter date:" << endl;
cin >> L.date;
WriteToFile << L.date;
}
void addtolist()
{
cout << "ur lists:" << endl; // and display the saved lists for the user to choose
ifstream readfromfile;
if (readfromfile.is_open())
{
makelist(); //the user adding new item
}
else
cout << "ERROR opening the file" << endl;
}
/*void checkitem() // function for displaying list from file for the user to chech them which i don't know how to do it
{}
void displaylist() // function displaying list from file which i also don't know how
{}*/
ps:i only know loops, array, functions, structs that's only my knowledge so far
i don't know anything except the above so i will need a full explanation i barely know how to write to a file.
and that's a sample of the supposed result
thanks in advance.