我想将我的程序从 c++ 翻译(或手动编译)成 HLA。程序读取输入的数字。然后减去三和十或仅十,确定该值是以零还是三结尾。连续三个这样的数字赢得比赛!一个不以这些数字结尾的值会输掉比赛。
我不知道如何在 HLA 中使用 AND 运算符连接的两个条件进行 while 循环。
while ((iend != 1) && (iscore < 3))
这是我用 C++ 编写的完整代码,我想把它翻译成 HLA:
#include <iostream>
using namespace std;
int main() {
int inum;
int iend = 0;
int iscore = 0;
int icheckthree; //To check if it ends in 3
int icheckzero; //To check if it ends in zero
while ((iend != 1) && (iscore < 3)) {
cout << "Gimme a number: ";
cin >> inum;
//Case 1: ends in three
icheckthree = inum - 3;
while (icheckthree > 0) {
icheckthree = icheckthree - 10;
if (icheckthree == 0) {
cout << "It ends in three!" << endl;
iscore++;
}
}
icheckzero = inum;
while (icheckzero > 0) {
icheckzero = icheckzero - 10;
}
//Case 2: ends in zero
if (icheckzero == 0) {
cout << "It ends in zero!" << endl;
iscore++;
}
//Case 3: Loose the game
else {
if (icheckzero != 0) {
if(icheckthree != 0) {
iend = 1;
}
}
}
if (iend == 1) {
cout << "\n";
cout << "Sorry Charlie! You lose the game!" << endl;
}
else if (iscore == 3) {
cout << "\n";
cout << "You Win The Game!" << endl;
} else {
cout << "Keep going..." << endl;
cout << "\n";
}
}
}