Hello,
I'm trying to write a Baseball Simulation Program and I need help.
The instructions are here http://wikisend.com/download/477216/baseball.doc
Instructions
OR IN THE Attached Files
I have a problem with the arrays.I also have a problem with getting the getline name of the players from the two files I have for Chicago and Tigers. I also have another file called inBall.txt ( 85 77 88 74 ) in it. I'm also stuck at the last functions win_loss(),print_results(),save_data(),read_roster(),announce_roster()
The program should include ofstream and instream to get the name of the players from the two files Chicago and Tigers.
I'm also getting errors.
code:
I'm trying to write a Baseball Simulation Program and I need help.
The instructions are here http://wikisend.com/download/477216/baseball.doc
Instructions
OR IN THE Attached Files
I have a problem with the arrays.I also have a problem with getting the getline name of the players from the two files I have for Chicago and Tigers. I also have another file called inBall.txt ( 85 77 88 74 ) in it. I'm also stuck at the last functions win_loss(),print_results(),save_data(),read_roster(),announce_roster()
The program should include ofstream and instream to get the name of the players from the two files Chicago and Tigers.
I'm also getting errors.
code:
#include <iostream> #include <fstream> #include <cmath> #include <string> #include <ctime> #include <Windows.h> using namespace std; void begin(); void pitch(); void batter_up(); void team_play(); int main() { begin(); team_play(); team_play(); team_play(); team_play(); team_play(); team_play(); team_play(); team_play(); team_play(); } void begin() { cout << "The teams that will be playing today are the" << endl << "Chicago White Sox and the Detroit Tigers." << endl; } void pitch() { int pitch = 0; Sleep(2500); srand ( time(NULL) ); pitch = rand() % 4 + 1; cout << "The pitcher threw a "; if(pitch == 1) { cout << "curveball" << endl; } if(pitch == 2) { cout << "fastball" << endl; } if(pitch == 3) { cout << "sinker" << endl; } if(pitch == 4) { cout << "slider" << endl; } } void batter_up() { int contact = 0; int ball = 0, strike = 0, out = 0,foul = 0; srand ( time(NULL) ); contact = rand()% 4 + 1; if(contact == 1) { int hit = 0; srand ( time(NULL) ); hit = rand()% 16 + 1; cout << "The batter hit a "; if(hit == 1 || hit == 2) { cout << "single " << endl; } if(hit == 3) { cout << "double" <<endl; } if(hit == 4) { cout << "triple" << endl; } if(hit == 5) { cout << "Home Run!!! " << endl; } if(hit == 6) { cout << "bunt "; int bunt = 0; bunt = rand()%4+1; if (bunt == 1) { cout << "single" << endl; } if(bunt == 2 || bunt == 3 || bunt == 4) { cout << "out" << endl; out = out + 1; } } if(hit == 7 || hit == 8 || hit == 9) { cout << "pop out" << endl; out = out + 1; } if(hit == 10 || hit == 11 || hit ==12) { cout << "fly out " << endl; out = out + 1; } if(hit == 13 || hit == 14 || hit == 15 || hit == 16) { cout << "ground out " << endl; out = out + 1; } } if(contact == 2 || contact == 3 || contact == 4) { int notHit = 0; srand ( time(NULL) ); notHit = rand() %5+1; if(notHit == 1 || notHit == 2) { cout << "The batter didnt swing and got a ball" << endl; ball = ball + 1; if(ball == 4) { cout << "The batter gets to walk a base" << endl; } } if(notHit == 3) { cout << "The batter got a strike" << endl; strike = strike + 1; if (strike == 3) { out = out + 1; cout << "The batter is out. " << endl; } } if(notHit == 4) { cout << "The batter swung and missed" <<endl; strike = strike + 1; if (strike == 3) { out = out + 1; cout << "The batter is out. " << endl; } } if(notHit == 5) { cout << "The batter hit a foul ball" <<endl; foul = foul + 1; if(strike < 2 || foul == 2); { out = out + 1; cout << "The batter is out. " << endl; } } } if ( out == 3) { cout << "Next team is up "; } } void team_play() { pitch(); batter_up(); } void read_roster(); { const int teams = 2; const int players = 9; string positions[players][teams]; string positions1[players][teams]; ifstream chicago; ifstream tigers; chicago.open("C:\\Documents and Settings\\student\\Desktop\\C_Baseball\\C++ Baseball\\Chicago.txt"); tigers.open("C:\\Documents and Settings\\student\\Desktop\\C_Baseball\\C++ Baseball\\Tigers.txt"); if (chicago.fail() || tigers.fail()){ cout << "\nAn input file could not be read."; cin.get(); exit(1); } for(int i = 0; i < players; i++){ chicago >> positions[i][0]; getline(chicago, positions[i][1]); } for(int i = 0; i < players; i++){ tigers >> positions1[i][0]; getline(tigers, positions1[i][1]); } for(int i = 0; i < players; i++){ cout << positions[i][0] << "\t"; cout << positions[i][1] << endl; } for (int i = 0; i < players; i++){ cout << positions1[i][0] << "\t"; cout << positions1[i][1] << endl; } chicago.close(); tigers.close(); } /* win_loss(); print_results(); save_data(); read_roster(); announce_roster() ; */
-
baseball.doc (47K)
: 2 -
Chicago.txt (160bytes)
: 2 -
Tigers.txt (166bytes)
: 2 -
inBall.txt (11bytes)
: 2