嘿家伙我正在写一个项目的代码的一部分,我坚持一件事。如果这是一些很好的编程人员在某个时刻自己弄清楚的话(因为我希望成为一名优秀的编程人员,第五周使用C++;迄今为止这么好......)以及它的一项试验,说出这个词,但是我一直在调试大约半个小时,不明白为什么我的'if'语句正在循环。为什么这个'if'语句循环?
输入应该是这样的:
p 11:34 12:45
其中p表示,如果你做(这将是 'S' 如果你想让它在这里用'end'表示)。
const int LIST_SPACE = 1000; // this is outside of the main function
string c; // and is 1000 because of a parameter set by the teacher
string end = "s";
string start = "p";
int temp_start_hour;
int temp_start_min;
int temp_end_hour;
int temp_end_min;
string colon = ":";
int begin_hours[LIST_SPACE];
int begin_min[LIST_SPACE];
int end_hours[LIST_SPACE];
int end_min[LIST_SPACE];
int i = 0;
do {
cin >> c; //where c is a string
if(c != start && c != end)
{
cout << "ERROR IN INPUT";
return 1;
}
if(c != end)
{
cin >> temp_start_hour >> colon >> temp_start_min;
cin >> temp_end_hour >> colon >> temp_end_min;
begin_hours[i] = temp_start_hour;
begin_min[i] = temp_start_min;
end_hours[i] = temp_end_hour;
end_min[i] = temp_end_min;
cout << begin_hours[i]; //I did this to check if it was storing values
i++;
}
}while(c != end); //ending the do-while loop
我真的很感激这个家伙正确的方向微调。或者关于我缺少的一个概念的建议。谢谢!
输出一直出现,顺便说一句是:(这是输入 'P 11:34 12:34')
11111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111Segmentation fault (core dumped)
这是一个家庭作业项目吗? – SpeedBirdNine
整个项目涉及比较调用列表以查看一个计划是否比另一个更好。你的问题的答案是肯定的,所以如果你不能帮助我理解,但是当我说投入几乎不能抓住这个项目的表面时,请相信我。真的,我只是在概念上混淆为什么会发生这种情况。 –
什么是“开始”和“结束”? – cnicutar