我被困住了。
我遇到了这个问题:http://i.imgur.com/1U8PjY4.png?1
到目前为止我写的代码是:
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
char cIn;
char full;
int capacity = 750;
int numVans = 1;
float heaviestVan = 0;
float payload = 0;
float parcelWeight;
bool emptyBelt = false;
int main()
{
bool end = false;
while(!end)
{
start:
cout << string(25, '\n');
cout << endl << "Pauls Premier Parcels (PPP)" << endl << endl;
cout << "Van being loaded is number: " << numVans << endl << endl;
cout << "The payload of van " << numVans << " is currently " << payload << " / 750kg" << endl << endl;
cout << "Is the belt full? ('Y' or 'N'): ";
cin >> full;
if (full == 'Y' || 'y')
{
while (!emptyBelt)
{
cout << endl << endl << "Please enter the weight of the next parcel: ";
cin >> parcelWeight;
if (parcelWeight > 120)
{
cout << "The maximum parcel weight is 120kg, please weigh a different parcel: ";
cin >> parcelWeight;
}
if (payload + parcelWeight <= capacity)
{
payload = payload + parcelWeight;
cout << endl << "The parcel has been loaded onto the van" << endl << endl;
goto start;
}
else
{
cout << endl << "The current van has reached capacity and is being dispatched" << endl;
//numVans = numVans + 1;
if(payload > heaviestVan)
{
heaviestVan = payload;
}
payload = 0;
cout << endl << endl << endl << "Vans dispatched: " << numVans;
cout << endl << endl << "Weight of heaviest van: " << heaviestVan;
}
}
}
}
return 0;
}
我需要实施一个声明,要求用户在皮带空的时候将包裹放在腰带上,现在它继续运行程序。
此外,用户还可以输入Y
或y
以外的任何内容,该程序仍可运行。
答案 0 :(得分:3)
尝试重写
if (full == 'Y' || 'y')
到
if ((full == 'Y') || (full == 'y'))
一些解释:
if (full == 'Y' || 'y')
与
相同if ((full == 'Y') || ('y'))
与
相同if ((full == 'Y') || true)
与
相同if (true)
无论变量full的值是多少。