我是一個初學者,所以請裸露在我這是我的代碼我必須得到無限的輸入,但是當兩個最近的一個相等的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