Hi,
the code's working fine in Linux.Am using Qt 4.4.3 on Fedora.
Better to put the code here,then more people are likely to test it out and tell you if they get any errors or can make sense of the errors you got.
fac1.cpp
#include <QtGui>
int main (int argc, char* argv[])
{
// Declarations of variables
int answer = 0;
do {
// local variables to the loop:
int factArg = 0;
int fact(1);
factArg
= QInputDialog::getInteger(0,
"Factorial Calculator",
"Factorial of:", 1);
cout << "User entered: " << factArg << endl;
int i=2;
while (i <= factArg) {
fact = fact * i;
++i;
}
.arg(factArg).arg(fact)
.arg("Do you want to compute another factorial?");
}
return EXIT_SUCCESS;
}
#include <QtGui>
int main (int argc, char* argv[])
{
QApplication app(argc, argv);
QTextStream cout(stdout);
// Declarations of variables
int answer = 0;
do {
// local variables to the loop:
int factArg = 0;
int fact(1);
factArg = QInputDialog::getInteger(0, "Factorial Calculator",
"Factorial of:", 1);
cout << "User entered: " << factArg << endl;
int i=2;
while (i <= factArg) {
fact = fact * i;
++i;
}
QString response = QString("The factorial of %1 is %2.\n%3")
.arg(factArg).arg(fact)
.arg("Do you want to compute another factorial?");
answer = QMessageBox::question(0, "Play again?", response,QMessageBox::Yes | QMessageBox::No);
}
while (answer == QMessageBox::Yes);
return EXIT_SUCCESS;
}
To copy to clipboard, switch view to plain text mode
fac1.pro
TEMPLATE = app
SOURCES += fac1.cpp
TEMPLATE = app
SOURCES += fac1.cpp
To copy to clipboard, switch view to plain text mode
Bookmarks