4 Replies - 1373 Views - Last Post: 13 May 2009 - 08:44 AM Rate Topic: -----

#1 alexKnight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 09

Baseball algorithm

Posted 11 May 2009 - 12:37 PM

Hey wassup guys I found this program online on some teachers website and I thought I would try it out for some practice. The program basically reads in a file with 9 innings showing the hits per inning. Then my job is to take that information and tally up the runs with the given hits per inning. I started working on it yesterday and I found myself stuck on an algorithm for tallying up the runs per inning for a team. I thought an algorithm for this would be to divide the number of hits by 4, which is an int and thats the runs scored. But thats not correct due to the fact that when an homerun is hit everyone on base including the hitter accounts for a run. I would appreciate it if someone can give me a hit on how to go about calculating the amount of runs per inning.


thanks!!

Is This A Good Question/Topic? 0
  • +

Replies To: Baseball algorithm

#2 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: Baseball algorithm

Posted 11 May 2009 - 12:41 PM

Do you think you could post what you have coded so far? Are you creating a class for this project?
Was This Post Helpful? 0
  • +
  • -

#3 alexKnight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 09

Re: Baseball algorithm

Posted 11 May 2009 - 12:49 PM

Thanks for the response!
But no apw5020 its not for a class project, its just summer and i want to get some practice writting code so I get alittle better.
But heres my code..
[code]
int readVistorAndTally( FILE *ptrToFile, char inning[][MAX_LENGTH]){
int i;
int runningHits= 0;
int same = 0;

for(i = 0;; i++){
fscanf( ptrToFile, "%s", &inning[i]);
if(strcmp(END_OF_VISTOR, inning[i]) == same){
printf("\n");
break;
}
if(strcmp(SINGLE_HIT, inning[i]) == same){
runningHits += 1;
}
else if(strcmp(DOUBLE_HIT, inning[i]) == same){
runningHits += 2;
}
else if(strcmp(TRIPLE_HIT, inning[i]) == same){
runningHits += 3;
}
else if(strcmp(HOMERUN, inning[i]) == same){
runningHits += 4;
}
else {
runningHits += 0;
}
}

return runningHits;
}

All this is is basically a function which job is to read the file (each inning) than return runs scored..but i cant seem to get a correct algorthim..thanks again guys!
Was This Post Helpful? 0
  • +
  • -

#4 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: Baseball algorithm

Posted 11 May 2009 - 01:06 PM

Sorry, I meant if you are creating a class in C++...

class someClass
{
public:

private:
};



Now I see you are using functions. I will take a look over it and get back to you soon.

By the way, you forgot the closing BBCode block after your code.

This post has been edited by apw5020: 11 May 2009 - 01:06 PM

Was This Post Helpful? 0
  • +
  • -

#5 alexKnight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 09

Re: Baseball algorithm

Posted 13 May 2009 - 08:44 AM

Yea im still stuck thinking about a scoring algorthim for the scoring in baseball!!
It's not just about adding all of the hits because the chronological order is critical.
It's been bothering me for quite some time.
I mean i know i can put an algorithm which specifies every single scenario but that doesn't seem every efficient.
Can somebody please give me a hint!
Thanks
:crazy:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1