Hello, Ive been taking an intro to C++ class and have been doing well until now. I have a problem with a "counter controlled loops". I get the idea of them, however I dont not know how to incorporate a way to prompt the user to open 1 out of 3 files.
Here is the actual question:
"This program is to be executed on three separate sets of
external file input data. Each set resides in a unique file.
Use a counter controlled for() loop to take care of the three
iterations. Within the loop you’ll have to implement an
interactive path-filename input routine, in order to
open-trap-process-close these external files. DO NOT “hardwire”
the path-filename in your code"
I hardwired the path and file name into my code to get it open.
I dont understand what would be counted to open up file 1, 2, or 3.
for(int counter = 0; i < 3; ++i) {
std::string filename;
std::cout << "Enter name of the file to open: ";
std::cin >> filename;
//There you should open file, process it and close.
}
DO NOT “hardwire” the path-filename in your code
[...]
I hardwired the path and file name into my code
I got that working, but nothing prints out to the output file when I enter the filename (which is located in my projects folder). Im trying to get something like this. I hate to ask for help, but im really stuck on this one.
int main()
{
double gpa;
double grade[4];// grades for student each student
double cgrade[10]; // totals course grades (down)
double avegpa[10]; // total course grade divided by number of students
int idnumber[10]; //id number
int numstd; // number of student
ifstream inputFile;
string filename;
int i=0;
for(int counter = 0; i < 3; ++i)
{
std::string filename;
std::cout << "Enter name of the file to open: ";
std::cin >> filename;
idnumber is an int, grade is a double. When you run into "Honors" string, you trying to enter string into either iny or double. Input stream error flag is set and everything went downstairs. Probably you should skip until the end of the line after reading id and grade to skip any notes you might encounter.