我一直在玩我的学位,并在一段时间内我的学位,我已经嵌套了另一个do()循环中的一些代码,但我遇到的问题是,代码不断,直到即使包裹的数量已满足,最后一辆面包车已满...(C++)代码似乎运行在错误的循环...?
代码如下。如果有人可以看看它,并告诉我我做错了什么,那很棒。裸记住,我才真正被用C++编码约一个月所以我还有很多海拉学习..
#include <iostream>
using namespace std;
char cBeltFull;
int iVanCount, iParcelCount, iParcelLoaded;
float fHeaviestVanWeight, fParcelWeight, fCurrentPayload, fVanCapacity;
char cExit = 'N';
int main() {
iVanCount = 1;
iParcelLoaded = 1;
fHeaviestWeight = 0;
fVanCapacity = 410;
do {
//Get the number of parcels to dispatch
cout << "How many parcels need sending?" << endl;
cin >> iParcelCount;
do {
fCurrentPayload = 0;
do {
//Get parcel weight
cout << endl << endl << endl << "What is the weight the parcel " << iParcelLoaded << "?";
cin >> fParcelWeight;
//'Load' the parcel
cout << endl << endl << "Parcel loaded";
iParcelLoaded ++;
//Update the payload
fCurrentPayload = fCurrentPayload + fParcelWeight;
} while ((fCurrentPayload + fParcelWeight)) < fVanCapacity)
//Dispatch the van
cout << endl << endl << "Van dispatched.";
//Update the van count
iVanCount ++;
if (fCurrentPayload > fHeaviestVanWeight) {
//Update the heaviest weight
fHeaviestVanWeight = fCurrentPayload;
}
} while (iParcelLoaded <= iParcelCount);
cout << endl << endl << endl << "Vans dispatched: " << iVanCout;
cout << endl << endl << "Weight of heaviest van: " << fHeaviestWeight;
cout << endl << endl << endl << "Exit? Y for YES or N for NO." << endl;
cin >> cExit;
} while (cExit == 'N');
}
你想实现什么? :)另外,“fHeaviestWeight”声明在哪里? – gsamaras 2014-11-06 18:41:40
嵌套的do-while循环,这是我很久没见过的东西。 – Borgleader 2014-11-06 18:42:17
@Borgleader有很好的理由:D – deW1 2014-11-06 18:42:41