I need to take the following code from a previous assignment are rewrite it using void functions. The code is very simple...but I'm confused on where to get started on this.I'm just now sure how to write this using a void function(s). Could I get some pointers please?
I would turn your infile/outfiles into functions first. In fact, I use both of those functions for all my assignments. So, you would do something like this:
You can do the same thing with your output file. Then in your main program, you would only have openInput();
where you currently have your other code. I don't know how much your teacher wants you to convert, but you could do the same thing with your output statement. You can make anything into a void function.
For your while loop, you just stick it all in a function, and then call the function instead of writing all that code in main.
I hope that helps.
:)
This is good so that you don't have to hard-code the filename into the function. Instead, it can be a variable that is received as input earlier on in the program like so:
1 2 3 4 5 6 7 8 9 10 11 12
#include <string>
#include <iostream>
usingnamespace std;
int main() {
string filename;
cout << "Please enter the filename: ";
getline(cin, filename);
openInput(filename);
}