我從教科書中運行此代碼:介紹使用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