473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

control break reading in a file

i am having some trouble getting this program to tally up the number of males and the number of females in each class and then adding them into a total i have been on this for hours now and i'm goin crazy man also the course number changes when i try to cout the course totals for 1301 it displays it as the totals for 1302 even though all the totals are correct for it to be 1301 please someone help


Expand|Select|Wrap|Line Numbers
  1. grades >> course >> name >> grade >> sex >> age ;
  2.   courseHold=course;
  3.  
  4.   while(!grades.eof())
  5.   {
  6.    if(course==courseHold)
  7.    {
  8.     cout << endl << course << "\t" << name << "\t" << grade << "\t" << sex << "\t" << age ;
  9.     count++;
  10.     ageSum+=age;
  11.     gradeSum+=grade;
  12.     avgAge=ageSum/count;
  13.     avgGrade=gradeSum/count;
  14.     grades >> course >> name >> grade >> sex >> age ;
  15.    }
  16.     else
  17.    {
  18.     cout << endl << endl << course <<"\t"<< avgGrade <<"\t"<< numMales <<"\t"<< numFemales <<"\t"<< avgAge << endl ;
  19.     avgGrade=gradeSum/count;
  20.     avgAge=ageSum/count;
  21.     grandAge+=ageSum;
  22.     grandGrade+=gradeSum;
  23.     totalCount+=count;
  24.     ageSum=0; gradeSum=0; count=0;
  25.     courseHold=course;
  26.    }
  27.   }
  28.    totalCount+=count;
  29.    grandAge+=ageSum;
  30.    grandGrade+=gradeSum;
  31.    avgAge=ageSum/count;
  32.    avgGrade=gradeSum/count;
  33.    grandAgeAvg=grandAge/totalCount;
  34.    grandAvg=grandGrade/totalCount;
  35.  
  36.    cout << endl << endl << course <<"\t"<< avgGrade <<"\t"<< numMales <<"\t"<< numFemales <<"\t"<< avgAge << endl << endl ;
  37.    cout << endl << endl << "All" << "\t" << grandAvg << "\t" << numMales <<"\t"<< numFemales <<"\t"<< grandAgeAvg << "\t" << endl << endl ;
  38.  
  39.    grades.close();
  40.  
  41.  
and the data file is this

Expand|Select|Wrap|Line Numbers
  1. 1301 Carol 87 F 21
  2. 1301 Bob 82 M 19
  3. 1301 Ann 93 F 18
  4. 1301 Carl 72 M 23
  5. 1302 Pete 87 M 19
  6. 1302 Jane 67 F 20
  7. 1302 Paul 74 M 18
  8. 1302 Cindy 98 F 24
  9. 1307 Juan 87 M 24
  10. 1307 Fred 61 M 25
  11. 1307 Jerry 77 M 30
  12. 1307 Carol 90 F 33
  13.  
Dec 5 '07 #1
0 1194

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roland Dalmulder | last post by:
Hello all, In my PHP script I put a text file into a string. Part of that string is read, changed and removed. The while loop continuest to extract the next part of the string. This goes all...
3
by: deko | last post by:
I'm trying to control the size of a log file. When it gets more than 5k oversize, I attempt to trim it thusly: $fcap = intval(($dval * 0.0108))*1024; // what it should be $fsize =...
0
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
1
by: marc-andr? | last post by:
Hi, I have to loop on each control on a webforms... I use this function : public void LoopOnAllControls(ControlCollection coll) { foreach (System.Web.UI.Control ctrl in coll) {
19
by: Noozer | last post by:
I need to keep my application settings in a file that users can copy/backup/etc. Before I start using the old INI file standard, is there any easy way to use XML files to hold application...
0
by: pabloazorin | last post by:
I developed a Date Picker web control using C# and .net framework 1.1 I added my control to Visual Studio 2003 IDE toolbar. When I drag and drop my control to design web page, the control renders...
5
by: pbearne | last post by:
Hi guys I am trying to this function below I have a web form with a load of inputs text boxs etc and i need to disable them So I have tried to write a function I can call and get the...
1
by: Vlad Dogaru | last post by:
Hello, I've written a simple, standalone wiki server in Python. It runs a BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is caught, at which point it writes changes to a file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.