A personal diary

Can someone help me improve my project. I am new to the programming field, and I am trying to make a project where the user can keep a diary. Right now my program is too simple. I have a menu that ask if the user wants to write a new entry open an old entry or exit the program. I got the exit choice to work, and I kind of got the write a new entry to work, but the problem is I can't have more than 1 entry.

p.s. I would also like to add dates and time to the program if someone could show me that. thank you

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  //headerfiles
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace 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\n";
			return 1;
			break;
		 default :cout<<"\a";
		}
		cin.ignore();
		cin.get();
	}while(ch!='3');
	return 0;
}
string newEntry(string entry1, int userID)
{
	ofstream outFile;
	outFile.open("journal.txt");
	if (outFile.fail())
	{
		cout << "Error could not open file.";
		return entry1;
	}
	int pw;
	cout << "Enter your userID: \n";
	cin >> pw;
	cin.ignore();
	if(pw == userID)
	{
  
	cout << "Whats on your mind\n\t" << endl;
	getline(cin,entry1);
	outFile << entry1;
	cout << endl << endl;
	}

	

	cout << "Entry submitted. \n\tpress enter to return to main menu\n";
	outFile.close();
	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.txt");
	if(!inFile)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}


	cout << entry1;
	}
	
}



This is my code so far.
Last edited on
Topic archived. No new replies allowed.