Sunday, July 12, 2009

C++ programing project I am stumped, I need to access the files from studenttests.dat and I can't figure?

#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;fstream%26gt;


#include %26lt;string%26gt;


#include %26lt;E:studenttests.dat%26gt;


using namespace std;








ifstream if1;











string LASTNAME, FIRSTNAME, TEST ONE, TESTTWO, TEST THREE;








int TESTONE ,TESTTWO ,TESTTHREE;


double FINALAVG;





void main()


{


cout%26lt;%26lt; " S T U D E N T G R A D E R E P O R T "%26lt;%26lt; endl ;


cout%26lt;%26lt; endl ;


cout%26lt;%26lt; "STUDENT TEST TEST TEST FINAL " %26lt;%26lt; endl ;


cout%26lt;%26lt; " NAME ONE TWO THREE AVG " %26lt;%26lt; endl ;


cout%26lt;%26lt; endl;











if1.open ("E:studenttests.dat");





if1%26lt;%26lt;setw(5)%26gt;%26gt;LASTNAME%26lt;%26lt;setw(21)%26lt;%26lt;FIRSTN...


%26lt;%26lt;LASTNAME%26lt;%26lt;FIRSTNAME%26lt;%26lt;TESTONE%26lt;%26lt;TESTTWO%26lt;...


%26lt;%26lt;LASTNAME%26lt;%26lt;FIRSTNAME%26lt;%26lt;TESTONE%26lt;%26lt;TESTTWO%26lt;...


cout%26lt;%26lt;endl;





if1.close;


and I am getting 3 errors or this????





ompiling...


Project3.cpp


e:\studenttests.dat(1) : error C2146: syntax error : missing ';' before identifier 'Bill'


e:\studenttests.

C++ programing project I am stumped, I need to access the files from studenttests.dat and I can't figure?
What are you doing, including studenttests.dat? You only include header files. studenttests.dat is an external file that has nothing to do with your C++ compilation process.





%26gt;%26gt; ifstream if1;





Move it out of the global space and into the main. Learn to not pollute your program with global variables.





%26gt; string LASTNAME, FIRSTNAME, ...





All caps names? Either make them all lowercase, or use a more sensible naming convention like CamelCaps (with the first letter lowercase).





And the whole no all caps names rule applies. Even though it's valid syntax, it's horrible convention.





%26gt; void main()





int main(). Not void main(). int. int. Can't repeat that enough.





%26gt; if1.open ("E:studenttests.dat");





Remove the E: part. Put studenttests.dat in the same folder as your executable program.





Get a proper book on C++ programming. If you don't want to do so, take a look at http://www.cprogramming.com/tutorial.htm...
Reply:"Project3.cpp


e:\studenttests.dat(1) : error C2146: syntax error : missing ';' before identifier 'Bill'


e:\studenttests."





Why is it trying to compile studenttests.dat? That looks like a problem. Do not compile studenttests.dat.
Reply:Remove The Following Statement


#include %26lt;E:studenttests.dat%26gt;


to resolve the problem.





There is another mistake in the program (i.e) in statement:


string LASTNAME, FIRSTNAME, TEST ONE, TESTTWO, TEST THREE;





Remove Space beteween TEST and ONE, and TEST and THREE,





Now Use the following statment instead:


string LASTNAME, FIRSTNAME, TESTONE, TESTTWO, TESTTHREE;





Also You can not declare 2 variables with different data types with same name. so remove the following statments:





int TESTONE ,TESTTWO ,TESTTHREE;


double FINALAVG;


No comments:

Post a Comment