Thursday, July 30, 2009

Basic C++ Programming Help?

Tryin to Read from input file an write results to output file. (Input txt appears as "m 3.00" etc.) Need some help in the right direction. I need: sum of female GPA,sum of male GPA,female count,male count,Average female GPA, Average male GPA





inData.open ("C++information.txt");


outData.open ("C++information_output.txt");





double malegpa = 0;


double femalegpa = 0;


int mcounter = 0;


int fcounter = 0;


double msum;


double fsum;


string males = "";


string females = "";


double femaleavg;


double maleavg;








inData%26gt;%26gt;males%26gt;%26gt;malegpa;


inData%26gt;%26gt;females%26gt;%26gt;femalegpa;





while (inData)


{








msum = ('m' + malegpa);





fsum = ('f' + femalegpa);





if (femalegpa == 'f')





fcounter++;





if (malegpa == 'm')





mcounter++;





msum = ('m' + malegpa);





fsum = ('f' + femalegpa);








}


outData%26lt;%26lt;"Sum female GPA = "%26lt;%26lt;fsum%26lt;%26lt;endl;

Basic C++ Programming Help?
A few little problems there. The main one is that your inData reads are outside the loop so only the first line of data is read. Also your syntax seems to add characters and doubles which may be legal C++ it is a meaningless thing to do. Oh heck, you also forgot to initialize msum and fsum.





Also are the male, female data lines interleaved? I suspect not. You want to read a line then sort which type it is.


No comments:

Post a Comment