在Visual Studio上编译失败,在Dev C ++上完美运行

时间:2017-09-18 16:06:11

标签: c++ visual-studio visual-studio-2017

出于某种原因,当我尝试在Visual Studios上编译和运行我的代码时,它告诉我我的编译失败了但是当我在Dev C ++上打开完全相同的.cpp文件时运行并完美地编译我的文件,没有任何错误,并提供正确的输出!我99%确定我的代码是正确的!我在视觉工作室的项目已经设置为子控制台。这是我第一次使用fstream,所以也许可以依靠它?

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

0 个答案:

没有答案