0

For some reason, when I try to compile and run my code on Visual Studios it's telling me that I've failed the compilation and but when I open the exact same .cpp file on Dev C++ it runs and compiles my file perfectly without any errors and gives the correct output! I'm 99% sure my code is correct! My project on visual studios is already set to subconsole. This is my first time working with fstream, so maybe it could rely on that?

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

class call_record
{
public:
    string cell_num;
    int relays, call_length;
    double net_cost, tax_rate, call_tax, total_cost;
};

void input(ifstream &, call_record &);
void processing(call_record &);
void output(const call_record &);

int main()
{
    call_record customer_records;

    ifstream in;
    in.open("call_data.txt");

    if (in.fail())
    {
        cout << "Input file did not open correctly!";
    }
    else
    {
        while (!in.eof())
        {
            input(in, customer_records);
            processing(customer_records);
            output(customer_records);
        }
    }

    in.close();

        return 0;
}

void input(ifstream & in, call_record & customer_records)
{

    in >> customer_records.cell_num;
    in >> customer_records.relays;
    in >> customer_records.call_length;
}

void processing(call_record & customer_records)
{
    customer_records.net_cost = (customer_records.relays / 50.0*0.40*customer_records.call_length);

    if (0 <= customer_records.relays && customer_records.relays <= 5)
    {
        customer_records.tax_rate = 0.01;
    }
    else if (6 <= customer_records.relays && customer_records.relays <= 11)
    {
        customer_records.tax_rate = 0.03;
    }
    else if (12 <= customer_records.relays && customer_records.relays <= 20)
    {
        customer_records.tax_rate = 0.05;
    }
    else if (21 <= customer_records.relays && customer_records.relays <= 50)
    {
        customer_records.tax_rate = 0.08;
    }
    else if (customer_records.relays > 50)
    {
        customer_records.tax_rate = 0.12;
    }

    customer_records.call_tax = (customer_records.net_cost*customer_records.tax_rate);

    customer_records.total_cost = (customer_records.net_cost + customer_records.call_tax);
}

void output(const call_record & customer_records)
{
    cout << setprecision(2) << fixed;
    cout <<"Cell Number: "<< customer_records.cell_num << "\t";
    cout <<"Relays: " << customer_records.relays << "\t";
    cout <<"Call Length: " << customer_records.call_length << "\t";
    cout <<"Net Cost: " << customer_records.net_cost << "\t";
    cout <<"Tax Rate: " << customer_records.tax_rate << "\t";   
    cout <<"Call Tax: " << customer_records.call_tax << "\t";
    cout <<"Total Cost: " << customer_records.total_cost << endl;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 4
    "Visual Studios it's telling me that I've failed the compilation" - you should post build log containing error message here. This code seems to be OK, it even uses meaningful names for methods and variables. – user7860670 Sep 18 '17 at 16:09
  • 1
    I have no problem compiling the code in VS2017. As a side note - you have to read https://stackoverflow.com/a/26557243/8491726 – Artemy Vysotsky Sep 18 '17 at 16:17
  • Hey guys!! I'm not sure why I didn't do this before, because I essentially wasted like 3 hours trying to figure out the problem, but I just restarted VS and now it works again... sorry T.T Btw, thank you for that link @ArtemyVysotsky !! Its such a good read!! – Meike Magdalena Büttner Sep 18 '17 at 16:39

0 Answers0