Help understanding (new)

Discussion in 'C++' started by Robert Garcia, Jan 29, 2021.

  1. Robert Garcia

    Robert Garcia New Member

    Joined:
    Jan 24, 2021
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Let me start by saying thanks for any help at all. the problem i am having is understanding using a function how to call a function to gather data from a file, have the file accept the good data and put the bad data in error file. The catch is we have to use a void function using ampersand. This is what i got so far but kind of hit a wall. Any help would be great, i am trying to hard to learn and understand what is taking place.
    Code:
    void getData(string name, int& num, int& infeet, double& incost, int& exfeet, double& excost, ifstream& inFile, ofstream& outFile, ofstream& errorFile, int& baddata);
    void calculation(int infeet, double incost, double& totalint, int exfeet, double excost, double totalext, double& total, ifstream& inFile, ofstream& errorFile);
    
    
    int main(){
    
    //opening input, output and error files
    ofstream outFile ("outfile.txt");
    ofstream errorFile ("errorFile.txt");
    ifstream inFile ("lab6.txt");
    
    string name;
    double incost, excost, intcost, extcost, total=0;
    double interiorCost, exteriorCost, totalint, totalext;
    int num, infeet, exfeet, linecount=0,
     baddata=false;
    
    int main(){
    
    //opening input, output and error files
    ofstream outFile ("outfile.txt");
    ofstream errorFile ("errorFile.txt");
    ifstream inFile ("lab6.txt");
    
    string name;
    double incost, excost, intcost, extcost, total=0;
    double interiorCost, exteriorCost, totalint, totalext;
    int num, infeet, exfeet, linecount=0, baddata=false;
    
    //Error message
    if (!outFile){
    cout << "Cannot open file, terminating the program. ";
    return 0;
    }
    if (!errorFile){
    cout << "Cannot open file, terminating the program.";
    return 0;
    }
    if (!inFile){
    cout << "Cannot open file, terminating the program.";
    return 0;
    }
    //loop eof
    while (!inFile.eof()){
    //read data
    getData(name, num, infeet, incost, exfeet, excost, inFile, outFile, errorFile, baddata);
    if(!baddata)   <-------( i am stuck here and wondering if i have the right approach)
    
    this is the data we are using:
    Data Fil
    ABC 1234 400 3.50 850 5.50
    DEF 1345 100 5.25 200 2.75
    GHI 2346 200 10.00 0 0.0
    JKL 4567 375 4.00 50 4.00
    MNO 5463 200 -5.0 150 3.00
    PQR 679 0 0.0 100 3.50
    STU 6879 100 0.0 -100 0.0
    VWX 7348 0 0.0 750 0.0
    XYZ 9012 -24 5.00 -50 5.00
     
  2. katejameson

    katejameson New Member

    Joined:
    Feb 16, 2021
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Female
    That looks interesting. but I can't find the issue.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice