#include <iostream> ;
#include <fstream>;
#include <string> ;
#include <iomanip> ;
using namespace std ;
int main ( )
{
string name;
int m1 ,m2, m3;
float avg;
ofstream outfile("mark.txt") ;
cout<<"Write your name :";
cin>>name;
cout<<"input 3 marks:";
cin>>m1>>m2>m3;
avg=m1+m2+m3/3.0;
cout <<showpoint << fixed << setprecision (2);
cout<<"ur average is :"<<avg<<endl;
outfile<<name<<m1<<""<<m2<<""<<m3;
outfile.close( );
return 0 ;
}

i need to find out whats the error

Use code tags:

[noparse]
[code]
// paste code here
[/code]
[/noparse]

The compiler will tell you exactly what the error is and where. Read the compiler messages closely. You'll get some warnings and an error. Read them carefully. Look at this line and see if you can find it:

cin >> m1 >> m2 > m3;

The warnings deal with the fact that you don't need semicolons at the end of the #include statements.

commented: two times faster and more accurate than me. you deserve the "posting virtuoso" stuff :D +1

cin>>m2>>m2>m3 missing one '>' before m3.

You shouldn't put ';' at the end of #includes, also.

Apart from that, you should be more specific when asking for help...

EDIT: Again you precede me, VernonDozier! :) My fault, I'm slow in replying 'cause I get distracted :P, btw yor answer is always more accurate ;-)

THNX Very much bro
100% correct it works

outfile<<name<<m1<<""<<m2<<""<<m3;

Why empty string literals?..
Where is the last line terminator ('\n') ? Your text file is ill-formed...

I am having a problem in the average it is not being saved ig i insert a student the other is gone

Do you mean in the output file? If so open it with ofstream outfile("mark.txt", ios::app) ; .

By doing so you will append your data to the file instead of rewriting it from scratch.

THNX it work :)

well the final thing i want to ask
i made a program to read the results for the above program
This is the code i wrote

// #include <iostream> 
#include <fstream>
#include <string> 
#include <iomanip> 
using namespace std ;
int main ( )
{
string name;
int m1 ,m2, m3;
float avg;
ifstream input ("mark.txt",ios::app) ;
input>>name>>m1>>m2>>m3;
avg=m1/3.0+m2/3.0+m3/3.0;
cout <<showpoint << fixed << setprecision (2);
cout<<name<<"  "<<avg<<endl;
input.close;
return 0 ;
}

well the final thing i want to ask
i made a program to read the results for the above program
This is the code i wrote

// #include <iostream> 
#include <fstream>
#include <string> 
#include <iomanip> 
using namespace std ;
int main ( )
{
string name;
int m1 ,m2, m3;
float avg;
ifstream input ("mark.txt",ios::app) ;
input>>name>>m1>>m2>>m3;
avg=m1/3.0+m2/3.0+m3/3.0;
cout <<showpoint << fixed << setprecision (2);
cout<<name<<"  "<<avg<<endl;
input.close;
return 0 ;
}

What's the question? Does it compile? Does it run, but then crash? Does it run to completion, but give bad results? Please provide more details.

If you open this file for input only you won't need ios::app

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.