Please help remove errors from the program

anybody help me remove the errors from the following C++ program ??? Please re post the code after the errors have been removed. People please help me.. i dont know anything a bout C++ programming.. this is my home work.. i dont know how to remove errors.. please help....


#include<fstream.h>
#include<conio.h>
struct emp
{
int emp_no;
char name[50];
long salary;
char dept[30];
}arr[50]; /*Data types of 4 records created*/

void main()
{
int n,i=0;
ofstream myfile;
myfile.open ("example.bin", ios::out | ios::app | ios::binary); /*Data file created*/
cout<<"How many records u want to enter - ";
cin>>n;
while(i!=n)
{
cout<<"\nEneter emp no for record "<<i+1<<":- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
//if (myfile.is_open())
{
myfile.write((char*) &arr[i],sizeof(arr[i])); /*Adding records to Data file*/
}
i++;
}
myfile.close();
ifstream mfile;
mfile.open ("example.bin", ios::in | ios::app | ios::binary);
cout<<"\nWhich record u want to modify-- ";
cin>>i;i--;
mfile.seekg(i,ios::beg);
cout<<"\nEneter emp no for record "<<i+1<<" :- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
mfile.read((char*) &arr[i],sizeof(arr[i])); /*Modifying the file*/
mfile.close();
getch();
}
Your homework is to remove errors, or to write the program? If your homework is to correct it, nobody will help you. Otherwise, could you elaborate, maybe tell us what lines have the errors?
Hi. To make our life a bit easier, would you mind posting your code inside [code]/*Code here!*/[/code] blocks? Much appreciated.

That aside, I agree with BR8N03epsilon. We could use an elaboration. :)

-Albatross
i dont know anything about c++... please help me or i will lose 15 marks from my final assessment !! please i m a noob
i dont know how to do C++ programming... i will lose marks from my school academic assessment..


PLEASE HELP !!! : (
I see two errors in the very beginning of the program. The first is that you should name standard C++ header files without extension that is instead of <fstream.h> should be <fstream> (if you are using a modern compiler). Also I see that you should include header <iostream>. And in C++ main is declared as int main()
Also, you don't have a using namespace std; anywhere in your program. Your C++ compiler won't know where to look for cout, cin, and ofstreams without that and without being prefixed by std::, like so:
1
2
3
std::cout /*etc*/;
std::cin /*etc*/;
std::ofstream myfile;


-Albatross
>> i dont know anything about c++... please help me or i will lose 15 marks from my final assessment !! please i m a noob


the mark you get for your assessment should reflect your understanding of the material you're supposed to have learned. If you're on a course and haven't learned anything, then why should you have any marks for it?
I agree with Bench 82. And you still haven't told us which lines have errors. Do you even have a compiler, or are you just trying to squeeze through the class so you can get a well-paying programming job which you'll only keep for two months until they realize that you don't know it? Not trying to be offensive, but if you try to work with us, you're more likely to get help.
Gentlemen,

you are requested not to give moral lectures. Instead, you shud help me out. Otherwise one year
will get wasted..

here is the code enclosed

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
#include<fstream.h>
#include<conio.h>
struct emp
{
int emp_no;
char name[50];
long salary;
char dept[30];
}arr[50]; /*Data types of 4 records created*/

void main()
{
int n,i=0;
ofstream myfile;
myfile.open ("example.bin", ios::out | ios::app | ios::binary); /*Data file created*/
cout<<"How many records u want to enter - ";
cin>>n;
while(i!=n)
{
cout<<"\nEneter emp no for record "<<i+1<<":- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
//if (myfile.is_open())
{
myfile.write((char*) &arr[i],sizeof(arr[i])); /*Adding records to Data file*/
}
i++;
}
myfile.close();
ifstream mfile;
mfile.open ("example.bin", ios::in | ios::app | ios::binary);
cout<<"\nWhich record u want to modify-- ";
cin>>i;i--;
mfile.seekg(i,ios::beg);
cout<<"\nEneter emp no for record "<<i+1<<" :- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
mfile.read((char*) &arr[i],sizeof(arr[i])); /*Modifying the file*/
mfile.close();
getch();
}
this seriously very important for me.. please help me and dont waste my time and your time passing comments...

instead help a helpless in disguise...
"How does Add/Remove Programs get the size and other information?"
http://blogs.msdn.com/oldnewthing/ar...09/178342.aspx










http://accessprogram.org
What course are you even on?
- If it isn't a programming one, why have you got this as homework?
- If it is a programming one, how do you not know anything at all about C++?
Are you exaggerating how much you don't know about C++, ie do you know the basics like cout << "Hey";, if statements etc?

You kind of keep just asking for help in the most vague way. "I don't know anything, just help me, fix these errors, come on help me, I'm gonna fail". I don't really think anyone has any idea about what you want doing.
Topic archived. No new replies allowed.