C++ Program have one error :)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 5
Reputation: king_blat is an unknown quantity at this point 
Solved Threads: 0
king_blat king_blat is offline Offline
Newbie Poster

C++ Program have one error :)

 
0
  #1
Nov 7th, 2008
#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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,832
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: C++ Program have one error :)

 
1
  #2
Nov 7th, 2008
Originally Posted by king_blat View Post
#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:


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




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, particularly the red, 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.
Last edited by VernonDozier; Nov 7th, 2008 at 1:01 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: C++ Program have one error :)

 
0
  #3
Nov 7th, 2008
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 , btw yor answer is always more accurate ;-)
Last edited by mrboolf; Nov 7th, 2008 at 1:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: king_blat is an unknown quantity at this point 
Solved Threads: 0
king_blat king_blat is offline Offline
Newbie Poster

Re: C++ Program have one error :)

 
0
  #4
Nov 7th, 2008
THNX Very much bro
100% correct it works
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: C++ Program have one error :)

 
0
  #5
Nov 7th, 2008
  1. outfile<<name<<m1<<""<<m2<<""<<m3;
Why empty string literals?..
Where is the last line terminator ('\n') ? Your text file is ill-formed...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: king_blat is an unknown quantity at this point 
Solved Threads: 0
king_blat king_blat is offline Offline
Newbie Poster

Re: C++ Program have one error :)

 
0
  #6
Nov 7th, 2008
I am having a problem in the average it is not being saved ig i insert a student the other is gone
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: C++ Program have one error :)

 
0
  #7
Nov 7th, 2008
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.
Last edited by mrboolf; Nov 7th, 2008 at 3:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: king_blat is an unknown quantity at this point 
Solved Threads: 0
king_blat king_blat is offline Offline
Newbie Poster

Re: C++ Program have one error :)

 
0
  #8
Nov 7th, 2008
THNX it work
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: king_blat is an unknown quantity at this point 
Solved Threads: 0
king_blat king_blat is offline Offline
Newbie Poster

Re: C++ Program have one error :)

 
0
  #9
Nov 7th, 2008
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
  1. // #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std ;
  6. int main ( )
  7. {
  8. string name;
  9. int m1 ,m2, m3;
  10. float avg;
  11. ifstream input ("mark.txt",ios::app) ;
  12. input>>name>>m1>>m2>>m3;
  13. avg=m1/3.0+m2/3.0+m3/3.0;
  14. cout <<showpoint << fixed << setprecision (2);
  15. cout<<name<<" "<<avg<<endl;
  16. input.close;
  17. return 0 ;
  18. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,832
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: C++ Program have one error :)

 
0
  #10
Nov 7th, 2008
Originally Posted by king_blat View Post
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
  1. // #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std ;
  6. int main ( )
  7. {
  8. string name;
  9. int m1 ,m2, m3;
  10. float avg;
  11. ifstream input ("mark.txt",ios::app) ;
  12. input>>name>>m1>>m2>>m3;
  13. avg=m1/3.0+m2/3.0+m3/3.0;
  14. cout <<showpoint << fixed << setprecision (2);
  15. cout<<name<<" "<<avg<<endl;
  16. input.close;
  17. return 0 ;
  18. }
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC