gpt4 book ai didi

c++ - 无限循环问题

转载 作者:行者123 更新时间:2023-11-30 01:22:48 25 4
gpt4 key购买 nike

<分区>

我正在处理一项必须计算运费的作业。出于某种原因,我在执行时遇到了无限循环。有人可以看看这个并帮助我,我无法确定原因。

代码:

#include <iostream> 
#include <iomanip>
#include <cmath>
#include <fstream>

using namespace std;

const double basic_charge = 12;
const double Vsurcharge = 5;
const double Dsurcharge = 4;
const double Wsurcharge = 2;

double calculate(double length, double width, double height)
{
double volume;
volume = length * width * height;
return volume;

}
int main ()
{

ifstream inFile;
ofstream prt("c:\\lab6a_out.txt");

double length, width, height, x, volume, weight, total, shipping_cost;
total = 0;

cout << " Shipping Information\n\n";
cout << "Length Width Height Weight Shipping\n";
cout << " Cost\n\n";

prt << " Shipping Information\n\n";
prt << "Length Width Height Weight Shipping\n";
prt << " Cost\n\n";

inFile.open("pkg6a.dat");
if (!inFile)
cout << "Error opening the file\n";

inFile >> length, width = 0, height = 0, weight = 0;

while (!inFile.eof())
{
shipping_cost = basic_charge;
volume = calculate (length, width, height);

if (volume > 7)
shipping_cost += Vsurcharge;
if (length > 3 || width > 3 || height > 3)
shipping_cost += Dsurcharge;
if (weight > 50)
shipping_cost += weight * Wsurcharge;

total += shipping_cost;

cout << setw(6) << right << setprecision(0) << length << setw(6) << right << width << setw(7) << right << height << setw(7) << right;
cout << weight << setw(9) << right << setprecision(2) << fixed << shipping_cost << endl;

prt << setw(6) << right << setprecision(0) << length << setw(6) << right << width << setw(7) << right << height << setw(7) << right;
prt << weight << setw(9) << right << setprecision(2) << fixed << shipping_cost << endl;

inFile >> length, width, height, weight;

}

cout << "\nTotal cost: " << total;
prt << "\nTotal cost: " << total;
//cin >> x;
return 0;



}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com