I'm working on a practice problem and I want to know if I have the right variables.
here's an example!!!
America’s National past time is Major League Baseball. The scoring for baseball is made
up of a diamond shaped infield with 3 bases and home plate. Players come up to bat and
try to get hits, so they can get on base and hopefully score runs. There are four different
kind of hits a player can get; a single (making it to first base), a double (getting to second
base), a triple (getting to third base) or a homerun (running around all four bases and
scoring, most of the time the ball is over the fence). Runners advance on hits if they are
already on base.
These are the variables I have down
Bases = 3, home plate, at bats, player on base, runs scored, hits = single(1st base), double(2nd base), triple (3rd base ), Home run(home plate), innings = 9 (while runs are equal at inning9 do inning +1 else return 0;), innings = Bottom, Top; outs = 1,2,3;
I know it looks stupid I just want to know if I'm on the right path???
i think the answer to your question is "YES" you are on the right track, but the way you wrote it is confusing. this would have been best presented in a pseudocode solution or actual code.
Just remember variable names can NOT contain spaces so things like player on base, runs scored, hits = single(1st base) etc will give you errors, unless you change names. to include underscores or CamelCase.
hey jason, i think its a great project to practice on, I started it myself, I am pretty much a beginner and learning the basics first through 'C++ A Beginner’s Guide' by Herbert Schildt ' . I am on chapter 5 if you are familiar with the writing.
anyhow, here is a partial program I wrote, so far i have one side up to bat then out, i dont have doubles or triples yet, just singles, strikes, balls, outs, foul balls, pitches. anyhow, check it out if you like!
I have a number of... displeasures with that code.
First of all, you shouldn't do his homework for him.
Second of all, the amount of gotos is ridiculous, you shouldn't even have to use one in that assignment.
Thirdly, you used the system() command unnecessarily. [1][2]
Fourth, your indentation is patchy and inconsistent, making your code hard to read.
Finally, don't do his homework for him.
thanks for the input chris :) like i stated in the above post, I have just started out in the programing world. I began c++ a few weeks ago through 'C++ A Beginner’s Guide' by Herbert Schildt' and have just been introduced to functions(chapter 5) today. I am sure as I go along and with your continuing positive feedback, I will progress on a stellar pace, lol,,, and btw,,, these posts i take on are ones that are good homework assignments for me.
Hey look guys
first of all this isn't homework my semester is done all ready
second of all I'm headed more towards doing it in a score card or record keeping format
Betty that looks nice it looks more like a gaming type code to where you can actually have a simulated game
Look the problem actually only asked for innings, strikes and runs
so everybody chill out with the Ciscal and Ebert Talk!!!
and I'd rather figure it out on my own this is just for sharing while on Christmas break
lmao @ ciscal and ebert, thanks jason:) i do however need to learn to neaten up my code and not depend on goto's so much,, i am learning functions now so I think thatll do the trick for the goto issue. it is a neat part of what will be a much larger program when its done, i think i will enjoy developing it. but once again, thanks for the input.
I eliminated the goto's and added functions to my baseball program, I tried to clean up the indents as best I could, I kept the system commands because the system pause helps the 'interaction' feel of the game, and the system cls is necessary to avoid clutter on the screen, so i kept those in until I learn something better that will achieve the same things.
void __sleep__(int ms) { /* This is just an example of a relatively cross-platform method of sleeping */
#ifdef _WIN32
Sleep(ms); /* Sleep() takes a parameter of milliseconds */
#else
sleep(ms / 1000); /* Whereas sleep() takes a parameter of seconds */
#endif
}
class KeepRunning { /* http://cplusplus.com/forum/beginner/1988/#msg7682 */
public:
~KeepRunning() {
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); /* Skip enter presses */
__sleep__(2000); /* Sleep 2 seconds */
}
};
}
As Grey Wolf explained later in that thread; if you create an instance of that KeepRunning class, e.g.
1 2 3 4 5
int main(void) {
KeepRunning _keep_running;
return 0;
}
before exiting, that destructor HAS to be called to destroy the _keep_running variable we placed on the stack. So regardless of what happens (even if you get abnormal termination) that code will always be called.