【发布时间】:2014-04-08 22:34:49
【问题描述】:
我正在尝试创建一个执行以下操作的程序:
公交车每次停靠,都要装卸乘客。每个公交车站下车的乘客数量必须随机生成。每个站点的候车人数也是随机生成的。公共汽车应在不超过公共汽车容量的情况下装载尽可能多的等候乘客。
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
void stop_bus(int); /* Stop the bus */
int unload_pass(int); /* Unload passengers */
int load_pass(int); /* Load passengers */
void start_bus(); /* Start the bus */
int main()
{
srand(time(0));
int stops = 7, currentStop = 1;
int maxPass = 50;
load_pass(maxPass);
while(currentStop < stops)
{
currentStop++;
stop_bus(currentStop);
unload_pass(maxPass);
load_pass(maxPass);
//start_bus();
}
system("pause");
return 0;
}
void stop_bus(int currentStop)
{
cout << "Currently at stop #" << currentStop << endl;
cout << "Please disembark the bus in an orderly fashion." << endl;
cout << endl;
}
int unload_pass(int maxPass)
{
int passOff;
int currentPass;
currentPass = load_pass(maxPass);
passOff = 1 + rand() % 50;
while (currentPass - passOff > 0 )
{
cout << currentPass << ": That number is not in the range." << endl;
passOff = 1 + rand() % 50;
cout << endl;
}
cout << "People leaving the bus: " << passOff << endl;
currentPass = currentPass - passOff;
cout << "Current bus load is " << currentPass << endl;
cout << endl;
cout << currentPass << ": That number is not in the range" << endl;
cout << endl;
return currentPass;
}
int load_pass(int maxPass)
{
int passOn;
int currentPass;
currentPass = unload_pass(maxPass);
passOn = 1 + rand() % 50;
while (currentPass + passOn > maxPass)
{
cout << currentPass << ": That number is not in the range" << endl;
passOn = 1 + rand() % 50;
cout << endl;
}
cout << "People boarding the bus: " << passOn << endl;
currentPass = currentPass + passOn;
cout << "Current bus load is " << currentPass << endl;
cout << endl;
return currentPass;
}
我很肯定我做错了。当我尝试运行它时,会弹出另一个窗口告诉我破解代码。这究竟是什么意思,我该如何解决?
【问题讨论】:
-
"弹出另一个窗口告诉我破解密码。"你能发布确切的错误信息吗?
标签: c++ visual-c++ int void