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;
}