#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
usingnamespace std;
string newEntry(string entry1, int userID);
void viewEntry(string entry1, int userID);
int main()
{
int ch;
int userID = 130464;
string entry1;
do
{
system("cls");
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. NEW JOURNAL ENTRY";
cout<<"\n\n\t02. VIEW JOURNAL ENTRIES";
cout<<"\n\n\t03. EXIT";
cout<<"\n\n\tSelect Your Option (1-3) ";
cin>>ch;
system("cls");
switch(ch)
{
case'1':
newEntry(entry1, userID);
break;
case'2':
viewEntry(entry1, userID);
break;
case'3':
cout<<"\n\n\tGoodbye";
break;
default :cout<<"\a";
}
cin.ignore();
cin.get();
}while(ch!='3');
return 0;
}
string newEntry(string entry1, int userID)
{
ofstream outFile;
outFile.open("journal");
if (!outFile)
{
cout << "Error could not open file.";
return entry1;
}
int pw;
cout << "Enter your userID: \n";
cin >> pw;
if(pw == userID)
{
cout << "Whats on your mind?" << endl;
getline(cin,entry1);
outFile << entry1;
}
return entry1;
}
void viewEntry(string entry1, int userID)
{
int pw;
cout << "Enter your userID:\n";
cin >> pw;
if(pw == userID)
{
ifstream inFile;
inFile.open("journal");
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout << entry1;
}
}
I've set up a menu for the user to choose whether the user wants to write a new journal entry or view previous journal entries. I then used a switch control so that whatever the user chooses, it would call the necessary function. However, when ever the user choose something from the menu, the screen just goes blank and it doesn't go to my other functions. I am probably missing a lot of necessary things, but any advice would be much appreciated! please and thankyou!
p.s.
I would also like the program to be able to store more user profiles and more journal entries. I have no idea where to start with this.