我是一个初学者,所以请裸露在我这是我的代码我必须得到无限的输入,但是当两个最近的一个相等的15之间的差异输出这两个数字。如何应用循环前提条件我有点困惑
#include <iostream>
#include <cstdlib>
using namespace std;
bool DiffCheck(int x, int y);
int main(int argc, const char * argv[]) {
int latest, prior;
cout << "Enter some integers:\n";
cin >> prior;
cin >> latest;
while (DiffCheck(latest, prior)) {
prior = latest;
cin >> latest;
}
cout << "The difference between " << prior << " and " << latest << " is greater than 15" << endl;
return 0;
}
bool DiffCheck(int x, int y)
{
return(abs(x - y) >= 15) ? false : true;
}
我只是想要一个先决条件,我想我可以自己完成剩下的工作,但是我只是为了了解我在做什么而写的。 – Jason
这是一个无效的停留时间循环...你也是什么意思的'先决条件'? – Li357
我认为precondition =预验证,或者简单地检查打破循环 – shole