我从教科书中运行此代码:介绍使用QT设计C++模式。C++代码导致可能的控制台输出错误
/* Computes and prints n! for a given n.
Uses several basic elements of C++. */
#include <iostream>
int main() {
using namespace std;
/*
*/
// Declarations of variables
int factArg = 0;
int fact(1);
do {
cout << "Factorial of: ";
cin >> factArg;
if (factArg < 0) {
cout << "No negative values, please!" << endl;
}
}
while (factArg < 0);
int i = 2;
while (i <= factArg) {
fact = fact * i;
i = i + 1;
}
cout << "The Factorial of " << factArg << " is: " << fact << endl;
return 0;
}
输出控制台只打印一行写着“阶乘是:” 难道这就是它想干什么?
它在我身边工作。你确定控制台允许执行输入吗? – vsoftco