Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- void openFile(ifstream& input)
- {
- string file = "superbowl.dat"; // declare a variable and set it equal to the name of the superbowl file
- input.open( file.c_str() ); // next open that file. doing file.c_str() tells the program to superbowl.dat in for file and then open that file.
- }
- void takeIn(ifstream& input, string winningTeam[], string losingTeam[], int finalScore[]) //made 3 arrays here that store, winning team, losing team, and final score. they are declared down in main. this is to make it easier to pass these arrays by reference later in the program.
- {
- for(int i = 0; i < 47; i++) // loops so that you can take in all of the games listed in the open file
- {
- input >> winningTeam[i]; //takes in the winning team
- input >> losingTeam[i]; // takes in the losing team
- input >> finalScore[i]; // takes in the score
- }
- }
- int main()
- {
- string winningTeam[48] = { };
- string losingTeam[48] = { };
- int finalScore[48] = { };
- ifstream input; // This says that we will now refer to our ifstream as input. this is important for the void openFile function
- openFile(input); // this runs the openFile function
- takeIn(input, winningTeam, losingTeam, finalScore); // this runs the takeIn function
- input.close(); // this closes the file stream
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement