473,387 Members | 1,510 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,387 software developers and data experts.

My program is giving me strange results

when i run my program it runs with no erorrs but the output screen is giving me strange results

here is whats its giving me:

CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
KSU 3-1 0.75 10.5 8-1 1.#IO 1.#J
CAP 3-1 0.75 11.75 7-2 1.#IO 1.#J
HEID 1-3 0.25 -4.00 3-4 1.#IO 1.#J
JCU 0-3 0.00 -9.75 2-5 1.#IO -1.#J
MAR 0-4 0.00 -29.75 2-7 1.#IO -1.#J
MUC 2-2 0.50 -6.25 4-4 1.#IO -1.#J
MUSK 1-2 0.25 -9.00 5-3 1.#IO 1.#J
ONU 3-1 0.75 15.25 7-2 1.#IO 1.#J
OTT 3-1 0.75 14.00 5-4 1.#IO 1.#J
WILM 3-1 0.75 7.25 7-2 1.#IO 1.



here is what its supposed to look like:
CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
1 KSU 3-1 .750 +10.50 8-1 .889 +13.56
1 CAP 3-1 .750 +11.75 7-2 .778 +13.67
1 ONU 3-1 .750 +15.25 7-2 .778 +17.78
1 OTT 3-1 .750 +14.00 5-4 .556 +7.56
1 WILM 3-1 .750 +7.25 7-2 .778 +10.00
6 MUC 2-2 .500 -6.25 4-4 .500 -0.50
7 MUSK 1-2 .333 -12.00 5-3 .625 +2.63
8 HEID 1-3 .250 -4.00 3-4 .429 +1.57
9 JCU 0-3 .000 -13.00 2-5 .286 -3.00
9 MAR 0-4 .000 -29.75 2-7 .222 -10.89



here is my code how should i fix to make it stop giving me those strange things:


Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <string>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. struct basketballStat
  11. {
  12.     string schoolName;
  13.     int numberWins;
  14.     int numberLosses;
  15.     int numberPointsTheTeamScored;
  16.     int numberPointsTheTeamScoredAgainst;
  17.     int teamOverallWins;
  18.     int teamOverallLosses;
  19.     int numberPointsTheTeamScoredInAll;
  20.     int numberPointsTheTeamScoredInAllAgainst;
  21.     int rank;
  22. };
  23.  
  24. struct basketballStatUpdate
  25. {
  26.     string date;
  27.     string nameOfHomeTeam;
  28.     int homeTeamsPointTotal;
  29.     string nameOfVisitTeam;
  30.     int VisitingTeamsPointTotal;
  31. };
  32.  
  33. void FormerStats (ifstream&, basketballStat&);
  34. void Updates (ifstream&, basketballStatUpdate&);
  35. void DoUpdate(basketballStat[], basketballStatUpdate&);
  36. void UpdatedStats(ostream&, basketballStat[]);
  37. void Standings(ostream&, basketballStat[]);
  38.  
  39.  
  40.  
  41. int main ()
  42. {
  43.     basketballStat formerStats[10];
  44.  
  45.     ifstream inFile1;
  46.     inFile1.open ("G:\\formerstats.txt");
  47.     ifstream inFile2;
  48.     inFile2.open("G:\\updates.txt");
  49.     ofstream outFile1;
  50.     outFile1.open ("G:\\updatedStats.txt");
  51.     ofstream outFile2;
  52.     outFile2.open ("G:\\standings.txt");
  53.  
  54.     for (int k=0; k<10; k++)
  55.     {
  56.         FormerStats (inFile1, formerStats[k]);
  57.     }
  58.  
  59.     while (!inFile2.eof())
  60.     {
  61.         basketballStatUpdate update;
  62.         Updates (inFile2, update);
  63.         DoUpdate(formerStats, update);
  64.     }
  65.  
  66.     inFile1.close();
  67.     inFile2.close();
  68.  
  69.     UpdatedStats(outFile1, formerStats);
  70.  
  71.  
  72.     outFile2<<setw(30)<<"CONFERENCE"<<setw(10)<<"OVERALL"<<endl;
  73.     outFile2<<"RANK"<<setw(6)<<"TEAM"<<setw(7)<<"W-L"<<setw(9)<<"% WINS"<<setw(11)<<"MARGIN"<<setw(8)<<"W-L"<<setw(9)<<"% WINS"<<setw(11)<< "MARGIN"<<endl;
  74.  
  75.     Standings(outFile2, formerStats);
  76.  
  77.  
  78.  
  79.  
  80.  
  81.     return 0;
  82. }
  83.  
  84. void FormerStats (ifstream &inFile1, basketballStat &myStat)  //this void function reads in the data from formerstats
  85. //within the basketballStat struct.
  86. {
  87.  
  88.     inFile1 >> myStat.schoolName;
  89.     inFile1 >> myStat.numberWins;
  90.     inFile1 >> myStat.numberLosses;
  91.     inFile1 >> myStat.numberPointsTheTeamScored;
  92.     inFile1 >> myStat.numberPointsTheTeamScoredAgainst;
  93.     inFile1 >> myStat.teamOverallWins;
  94.     inFile1 >> myStat.teamOverallLosses;
  95.     inFile1 >> myStat.numberPointsTheTeamScoredInAll;
  96.     inFile1 >> myStat.numberPointsTheTeamScoredInAllAgainst;
  97. }
  98.  
  99. void Updates (ifstream& inFile2, basketballStatUpdate &update) //this void function reads in the data from updates.txt and
  100. //struct called basketballStat update is being used to read in the data.
  101. {
  102.  
  103.     inFile2 >> update.date;
  104.     inFile2 >> update.nameOfHomeTeam;
  105.     inFile2 >> update.homeTeamsPointTotal;
  106.     inFile2 >> update.nameOfVisitTeam;
  107.     inFile2 >> update.VisitingTeamsPointTotal;
  108. }
  109.  
  110. void DoUpdate(basketballStat myStat[], basketballStatUpdate &update) // this function updates the stats of the conference games
  111. // and calculates each data for each game and updates it into a recent and update form of the stats in the conference games. 
  112. {
  113.     bool homeOfTheConfTeam = false, visitConfTeam = false;
  114.     int homeTeamIndex, visitTeamIndex;
  115.     for (int j=0; j<10; j++)
  116.     {
  117.         if (myStat[j].schoolName==update.nameOfHomeTeam) 
  118.         {
  119.             homeOfTheConfTeam = true;
  120.             homeTeamIndex = j;
  121.         } else if (myStat[j].schoolName==update.nameOfVisitTeam) 
  122.         {
  123.             visitConfTeam = true;
  124.             visitTeamIndex = j;
  125.         }
  126.         if (homeOfTheConfTeam&&visitConfTeam) break;
  127.     }
  128.  
  129.     bool homeWin = (update.homeTeamsPointTotal > update.VisitingTeamsPointTotal);
  130.  
  131.     if (homeOfTheConfTeam) 
  132.     {
  133.         myStat[homeTeamIndex].numberPointsTheTeamScoredInAll += update.homeTeamsPointTotal;
  134.         myStat[homeTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.VisitingTeamsPointTotal;
  135.         if (homeWin)
  136.             myStat[homeTeamIndex].teamOverallWins++;
  137.         else
  138.             myStat[homeTeamIndex].teamOverallLosses++;
  139.     }
  140.     if (visitConfTeam) 
  141.     {
  142.         myStat[visitTeamIndex].numberPointsTheTeamScoredInAll += update.VisitingTeamsPointTotal;
  143.         myStat[visitTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.homeTeamsPointTotal;
  144.         if (!homeWin)
  145.             myStat[visitTeamIndex].teamOverallWins++;
  146.         else
  147.             myStat[visitTeamIndex].teamOverallLosses++;
  148.     }
  149.     if (homeOfTheConfTeam&&visitConfTeam) 
  150.     {
  151.         myStat[homeTeamIndex].numberPointsTheTeamScored += update.homeTeamsPointTotal;
  152.         myStat[homeTeamIndex].numberPointsTheTeamScoredAgainst += update.VisitingTeamsPointTotal;
  153.         myStat[visitTeamIndex].numberPointsTheTeamScored += update.VisitingTeamsPointTotal;
  154.         myStat[visitTeamIndex].numberPointsTheTeamScoredAgainst += update.homeTeamsPointTotal;
  155.         if (homeWin) 
  156.         {
  157.             myStat[homeTeamIndex].numberWins++;
  158.             myStat[visitTeamIndex].numberLosses++;
  159.         } else
  160.         {
  161.             myStat[visitTeamIndex].numberWins++;
  162.             myStat[homeTeamIndex].numberLosses++;
  163.         }
  164.     }
  165. }
  166.  
  167. void UpdatedStats(ostream &outFile1, basketballStat myStats[])// this  function stores the calculations from the upbove function
  168. // and uses a set of arrays to write the updated stats data in the outfile1.
  169. {
  170.     for (int m=0; m<10; m++) 
  171.     {
  172.         outFile1 << myStats[m].schoolName << " ";
  173.         outFile1 << myStats[m].numberWins << " ";
  174.         outFile1 << myStats[m].numberLosses << " ";
  175.         outFile1 << myStats[m].numberPointsTheTeamScored << " ";
  176.         outFile1 << myStats[m].numberPointsTheTeamScoredAgainst << " ";
  177.         outFile1 << myStats[m].teamOverallWins << " ";
  178.         outFile1 << myStats[m].teamOverallLosses << " ";
  179.         outFile1 << myStats[m].numberPointsTheTeamScoredInAll << " ";
  180.         outFile1 << myStats[m].numberPointsTheTeamScoredInAllAgainst << " " << endl;
  181.     }
  182.  
  183. }
  184. void Standings(ostream &outFile2, basketballStat myStats[])
  185. {
  186.     float total=4.0;
  187.     //float answer=9;
  188.     for(int j=0; j<10; j++)
  189.     {
  190.         //outFile2<<myStats[j].rank<<endl;
  191.         outFile2<<setw(14)<<myStats[j].schoolName;
  192.         outFile2<<setw(10)<<myStats[j].numberWins<<'-';
  193.         outFile2<<myStats[j].numberLosses;
  194.         outFile2<<setw(8)<<myStats[j].numberWins/total;
  195.         outFile2<< setw(13)<<(myStats[j].numberPointsTheTeamScored-myStats[j].numberPointsTheTeamScoredAgainst)/total<<" ";
  196.         outFile2<<setw(12)<<myStats[j].teamOverallWins<<'-';
  197.         outFile2<<myStats[j].teamOverallLosses;
  198.  
  199.  
  200.  
  201.     float numberGamesTotalPlayed=0;
  202.     if(numberGamesTotalPlayed<=10)
  203.     {
  204.  
  205.         outFile2<<setw(8)<<fixed<<setprecision(3)<<myStats[j].teamOverallWins/numberGamesTotalPlayed;
  206.         outFile2<<setw(8)<<fixed<<setprecision(2)<<(myStats[j].numberPointsTheTeamScoredInAll-myStats[j].numberPointsTheTeamScoredInAllAgainst)/numberGamesTotalPlayed<<endl;
  207.  
  208.     }
  209.     }
  210.  
  211.  
  212. }
  213.  
  214.  
Dec 8 '08 #1
0 1302

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

Similar topics

1
by: Dan Stromberg | last post by:
The below small program is giving strange behavior. At the bottom of the code, please find "this works" and "this doesn't work" comments. Why does one work and the other not? TIA. ...
1
by: Hunter Hillegas | last post by:
I have just added a third table to a query and I am no longer getting the results I am expecting. Three Tables: CUSTINVOICEJOUR (Header Table) CUSTINVOICETRANS (Line Item Table) MARKUPTRANS...
10
by: Nimit | last post by:
Hi, I wasn't sure which forum this post belongs to, so I've posted it to a couple forums that I thought may be appropriate. In giving me advice, please consider me a beginner. Below is a synopsis...
10
by: bear | last post by:
hi all, I have a program whose speed is so strange to me. It is maily used to calculate a output image so from four images s0,s1,s2,s3 where so=(s0-s2)^2+ (s1-s3)^2. I compile it with gcc (no...
4
by: vagrantbrad | last post by:
I'm using python 2.4 running on Fedora Core 4. I have written a python program called ipscan.py that checks the external ip address of my cable internet connection, and on change, will update the...
17
by: Gladiator | last post by:
When I am trying to execute a program from "The C Programming Language" by Dennis Ritchie, I tried to run the following program.I am using Dev++ as a compiler software. The Program is presented...
2
by: manontheedge | last post by:
I'm getting weird results in my program, and even compile time errors, and I've got it down to the "\n" command I use in "printf()". The program this is happening in deals with multiple processes,...
19
by: pitamber kumar | last post by:
Write a program to find the number of and sum of all intergers greater than 100 & less than 200 that are divisible by 7.
87
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.