Please tell me what these errors mean?

Please tell me what's wrong with the code. I'm a beginner.

https://www.box.com/s/b5va4zu1nnlj15l2mldc


It's for my school project. Thanks in advance :)


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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

class student{
	int admno;
	int class_rollno;
	char name[30];
	char mobileno[11];
	float marks[5];
	float fees;
public:
	int getadmno(){return admno;}
	int getclass_rollno(){return class_rollno;}
};






int main(){
student s1;//To read and write to the database.
int main_menu_choice,admin_menu_choice;//main_menu_choice for the main menu options.
//admin_menu_choice for the admin menu option.
char menu_choice_1;//Do..while loop in level 2 menu.
char main_menu_continue,admin_menu_1='y';//main_menu_continue to loop contents in main()
//admin_menu_1 is used with do..while loop in the admin menu.
int passkey;//stores the passkey which the user inputs.
int psk;//stores the passkey after reading it from a file.
int admin_check=0;//To check if the user has admin rights.
int newpass;//To change the passkey.
char ans;

do{
clrscr();


cout<<"\t\t\tSTUDENT DATABASE MANAGEMENT SYSTEM\n\n";

//If the passkey hasn't been entered already,
//the program will ask the user to enter one.
//The user can also change the passkey at the starting of the program only...



if(admin_check==0){
cout<<"\nDo you have the admin passkey? This will be used to access functions marked with '(*)'";
cout<<"\n1.Login\t2.Change passkey\t3.Skip.";
}

//Read the passkey file.
ifstream pass;
pass.open("pass.txt",ios::in);
//Store the passkey read from the file in a variable psk;
pass.getline(psk,40,'\n');
pass.close();


if(admin_menu_choice==1)
{
//The user may retry entering the passkey, if the entered passkey is incorrect.
       do{
		cout<<"\nEnter the passkey.";
		cin>>passkey;
		if(passkey==psk)
		admin_check=1;
		else{
		cout<<"\nThe entered passkey is wrong! Do you want to retry?(Y-Yes||Any other key-No)";
		cin>>admin_menu_1;
		}
	}while(admin_menu_1=='y'|admin_menu_1=='Y');
}

if(admin_menu_choice==2)
{
//Open passkey file in output mode.
//The user may change the passkey. To change the passkey, the user must
//first enter the old passkey.
			do{
				cout<<"\nEnter existing passkey.";
				if(passkey==psk)
				admin_check=1;
				else{
				cout<<"\nThe entered passkey is wrong! Do you want to retry?(Y-Yes||Any other key-No)";
				cin>>admin_menu_1;
			}while(admin_menu_1=='y'|admin_menu_1=='Y');


		cout<<"\nEnter new password";
		cin>>newpass;
		ofstream outpass;
		outpass.open("pass.txt",ios::out);
		outpass<<newpass;
		outpass.close();

}

cout<<"Do you want to?\n1.Access basic student information.\n2.Access secure student information.(*)\n3.Edit the database.(*)\n4.Append to the database.(*)\n0.Create a new Database-Deletes the existing database(*)\n";
cout<<"\nEnter your choice (1/2/3/4/0)\t";
cin>>main_menu_choice;


if(main_menu_choice!=0||main_menu_choice!=1||main_menu_choice!=2||main_menu_choice!=3||main_menu_choice!=4)
{
	clrscr();
	cout<<"\n\n\t\tYou have entered a wrong choice.\n\n";
}

if(main_menu_choice==0){

//   if(admin_check!=1)//check if user has admin rights.
//   {
//	cout<< "\nYou do not have admin rights.\n";
//	break;
//   }

ofstream std(student.dat,ios::out||ios::binary);

	  do{
		clrscr();
		cout<<"\nCreating database. Old records have been removed.\n"

		while(ans=='y'||ans=='Y'){
		std.write((char*)&s1,sizeof(s1));
		cout<<"\nDo you want to enter another record?(Y-Yes||Any other key-No)";
		cin>>ans;
	  }while(ans=='y'|ans=='Y');
std.close();
	ans='n';
   }


if(main_menu_choice==1){

	do{
		clrscr();
		cout<<"\n\t\tAccess basic student information::\n";
		cout<<"a.Print all data\nb.Sort the data\nc.Edit data.\nd.Delete at a paricular position\n";
		cout<<"\nPlease enter your choice (a/b/c/d)\t";
		cout<<"\n\nDo you want to continue?(Y-Yes||Any other key-No)\t";
		cin>>menu_choice_1;
	}while(menu_choice_1=='y'|menu_choice_1=='Y');
}













cout<<"\nDo you want to continue?(Y-Yes||Any other key-No)\t";
cin>>main_menu_continue;


}while(main_menu_continue=='y');

return 1;
}
Last edited on
I can't actually see your code on that link.

Copy & paste your code into your post above - make sure to select all the code, then format it with the code tags button <> on the right

This will make your code much easier to read.

Also post your compiler output in full, so we can see what the errors are.

Hope this helps.
Updated the question: added the code.
Sorry, but name (project)?? Description?? How it works??? Why you sad?? What point that makes you sad??
Sorry, we (and I) currently cannot answer your general question. This requires more information to be more understandable, also you'll get more helps, suggestions and comments from other people. :)
Please post your compiler output ( the errors)
These are some of the things I can see:

In general you need to split your code into functions. There is a bit of a rule that a function should not be more than 80 lines of code. And no more than 80 chars per line of code. You should have a function that prints the menu and then another to get a response and call the appropriate function to carry out the menu option. The processing of the menu option should be a switch statement, with each case calling a function.

You have a lot of these:

}while(menu_choice_1=='y'|menu_choice_1=='Y');

You need to use the || (Or operator) not |

If you make use of the toupper function (converts a char to upper case) you won't have to test the variable twice.

I personally dislike do loops, here is a better way of quitting from something:

1
2
3
4
5
6
7
8
bool Quit  = false;

while (!Quit) {
//your code

//user wants to quit 
Quit = true;
}


Also with variable names - I like to use CamelCase. No underscores - they make the name too long, capitalise the first letter of each word.

Now with your objects, To process multiple students, create a student object then use push_back to put it into a vector. This way you can store all the info.

With this:
if(main_menu_choice!=0||main_menu_choice!=1||main_menu_choice!=2||main_menu_choice!=3||main_menu_choice!=4)

What if you had 15 menu options? There has to be a better way. Hint - the switch statement I mentioned earlier.

Hope all goes well.


edit:

You can build up the cout in stages - it doesn't have to be all on one giant long line - like this:

1
2
3
4
5
6
7
8
cout<<"Do you want to?\n";
cout << "1.Access basic student information.\n";
cout << "2.Access secure student information.(*)\n";
cout << "3.Edit the database.(*)\n";
cout << "4.Append to the database.(*)\n";
cout  << "0.Create a new Database-Deletes the existing database(*)" << endl;
cout<<"\nEnter your choice (1/2/3/4/0)\t" << endl;


You should also have an option to end the program on the menu. And as I said earlier the whole thing should be in a function.
Last edited on
Another tip for you : If you can't find what's wrong in your code, put some halt (block) functions (or code) at a place (where you doubt). There are many halt functions such as (simplest : return (ErrorCode)), exit(int nCode), Sleep(int nMiliseconds), ExitProcess(int nExitCode),...
If the problem is not serious (Causes crashes or not), maybe you have to check the values of important variables. Try logging the variable(s) you want at anywhere you doubt, and I think it should be detected & solved soon.
(A powerful & helpful trick from my programming experience)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define ErrorCode 174

int main()
{
//Where you think it will occur
[...]
return ErrorCode; //Simplest for beginner
//Continue executing
////////////////////////////////////////
//Where you think the result will wrong
cout << <Variable>...
[...]
return 0; //No Error
}


And @TheIdeasMan (1214) : I agree with you completely about your code tweaking & optimization
if(main_menu_choice!=0||main_menu_choice!=1||main_menu_choice!=2||main_menu_choice!=3||main_menu_choice!=4)

Should be changed to
1
2
3
4
5
6
7
8
9
switch(main_menu_choice){
case 0 : [...] break;
case 1 : [...] break;
case 2 : [...] break;
case 3 : [...] break;
case 4 : [...] break;
default : //wrong choice
[...]
}


With a loop condition... (Also my favorite code)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
while(1)
{
[...] //code

if([...]) //Small errors detected or unnoticeable events (Optional)
{
[...] //Do something
continue; //Prepare the next loop immediately
}

if([...]) // A critical events or serious error detected
{
[...] //Do something
break;// Break the loop immediately 
}

}
@Novice Coder Alpha

I wouldn't listen too much to Jackson Marie (22) I think that his / her advice is intentionally bad to provoke comment - also known as trolling.

For example suggesting an infinite while loop is particularly bad advice for a beginner coder.

As for the terrible debugging advice, you would be better to learn how to use the debugger.

Now, is there a reason you are using a really old Borland compiler? Is that what your school has? Do you have your own computer?

If you don't have access to anything else, then you will have to stick with it.

If you have your own computer, you could download any one of the free compiler / IDE software, which would be a million times better.
Thank you all :)
Topic archived. No new replies allowed.