vendredi 25 juin 2021

IF Statement in File Input Loop

I trying to get the user to open a file on this assignment for school. Everything was going according to the instructions that my professor gave. But in this step: "To determine to which of the four files to write the data for the current student, use a decision structure (a series of if statements or a switch structure). Compare the variable storing the character representing the student’s major to each of the four values, one in each if statement or case. The statement executed for each if statement or case should be an output statement that uses the ofstream variable for the corresponding file and each of the five variables (excluding the major code character) to be written for the student." Basically, writing "if" statement in a "while" loop. Now the question is "WHAT GOES IN THE BOOLEAN EXPRESSION??!!" The professor did not specify what goes into the expression.

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main ()
{
  int gpa, studentnumber;
  string lastname, firstname;
  char middle, majorcode;
  ifstream cisdegree;
  ofstream appmajors, netmajors, progmajors, webmajors;

  cisdegree.open ("cisdegree.txt");
  if (cisdegree.fail ())
    {
      cout << "Error opening input file. \n";
      exit (1);
    }

  appmajors.open ("appmajors.txt");
  netmajors.open ("netmajors.txt");
  progmajors.open ("progmajors.txt");
  webmajors.open ("webmajors.txt");

  appmajors.setf (ios::fixed);
  appmajors.setf (ios::showpoint);
  appmajors.precision (2);

  netmajors.setf (ios::fixed);
  netmajors.setf (ios::showpoint);
  netmajors.precision (2);

  progmajors.setf (ios::fixed);
  progmajors.setf (ios::showpoint);
  progmajors.precision (2);

  webmajors.setf (ios::fixed);
  webmajors.setf (ios::showpoint);
  webmajors.precision (2);

  cisdegree >> studentnumber >> lastname >> firstname
    >> middle >> gpa >> majorcode;

  while (!cisdegree.eof ())
    {
      cisdegree >> studentnumber >> lastname >> firstname
    >> middle >> gpa >> majorcode;
      if (appmajors)
        {
            studentnumber << lastname << firstname
            << middle << gpa << "A";
        }

    }



  appmajors.close ();


  return 0;
}

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire