void checkAnswer (int toguess, int counter){ int guessed; printf("Bitte geben sie ihre Zahl ein: "); do {scanf("%i",&guessed);} while (getchar() != '\n'); if (guessed < toguess) {printf("Die Zahl ist größer!\n"); checkAnswer (toguess,counter+1);} else if (guessed > toguess) {printf("Die Zahl ist kleiner!\n"); checkAnswer (toguess,counter+1);} else {printf("Du hast die Zahl erraten!\n"); askForSave(counter); } }
int main() { int answer, count=5; int a, b, n; int goodAnswers=0, badAnswers=0; while( count-- ){ a=random(); b=random2(); printf("%i * %i = ", a, b); getResult(&answer); n = checkAnswer(a, b, answer); giveFeedback(n, a, b); if( n==1 ) goodAnswers +=1; else badAnswers +=1; } printf("\nYou got %i answer(s) correctly and %i answer(s) incorrectly!\n\n", goodAnswers, badAnswers); return 0; }
void EditAccountDialog::chooseQuery() { ThreadControl *tc = qobject_cast<ThreadControl *>( sender() ); if( !tc ) return; int i = tc->getIndexOfLastQuery( qList ); if( i < 0 ) return; QStringList list = tc->getDataList(); switch(i) { case 0: { if( list.count() >= 1 ) loadData( list.first() ); break; } case 1: { if( list.count() >= 1 ) checkAnswer( list.first() ); break; } case 2: { if( list.count() >=1 ) changeOwnerAnswer( list.first() ); break; } } }
int main(int argc, char *argv[]){ int counter = 0; srand(time(0)); checkAnswer ((irand(0,100)),0); return EXIT_SUCCESS; }
MainView::MainView( QWidget *parent ) : QWidget( parent ) { QGridLayout *topLayout = new QGridLayout( this ); topLayout->setSpacing( 8 ); topLayout->setMargin( 8 ); QLabel *label = new QLabel( i18n("Question:"), this ); topLayout->addWidget( label, 0, 0 ); mQuestionLabel = new QLabel( this ); QFont f = mQuestionLabel->font(); f.setPointSize( 30 ); mQuestionLabel->setFont( f ); mQuestionLabel->setAlignment( AlignCenter ); topLayout->addWidget( mQuestionLabel, 1, 0 ); label = new QLabel( i18n("Answer:"), this ); topLayout->addWidget( label, 2, 0 ); mAnswerEdit = new QLineEdit( this ); topLayout->addWidget( mAnswerEdit, 3, 0 ); connect( mAnswerEdit, SIGNAL( returnPressed() ), SLOT( checkAnswer() ) ); mAnswerEdit->setAlignment( AlignCenter ); mOkButton = new QPushButton( i18n("Ok"), this ); topLayout->addWidget( mOkButton, 4, 0 ); connect( mOkButton, SIGNAL( clicked() ), SLOT( checkAnswer() ) ); mFeedbackText = new QLabel( this ); topLayout->addWidget( mFeedbackText, 5, 0 ); mFeedbackText->setFrameStyle( QFrame::Panel | QFrame::Plain ); mFeedbackText->setLineWidth( 2 ); mFeedbackText->setAlignment( AlignCenter ); QFontMetrics fm( mFeedbackText->font() ); mFeedbackText->setFixedHeight( fm.height() * 3 + 6 ); // mResultView = new ResultViewText( this ); mResultView = new ResultViewPic( this ); topLayout->addMultiCellWidget( mResultView, 0, 5, 1, 1 ); connect( &mReadyTimer, SIGNAL( timeout() ), SLOT( setReady() ) ); }
void boxAsker::init() { p_accept -> setText(i18n("&Accept")); resetAnswers(); clearAsked(); nextQuestion(); p_accept -> disconnect(); connect(p_accept, SIGNAL(clicked()), this, SLOT(checkAnswer())); }
int main(int argc, char *argv[]){ // Instantiate tallied variables. int i, j, width, correct, hintCount, guesses, hints, trys; //Instantiate stats array int stats[5] = {0}; // Determine width of Matrix width = getWidth(argc, argv); // Generate matrix based on width complex** M = generateMatrix(width); // Create randmom number generator. srand((unsigned)time(NULL)); // Create string array for user input. char choice[20]; // Create array of type complex to store generated row column pairs complex uniques[width * width]; // Continue game until user quits. while(strncmp(choice, "Q", 1) != 0){ // Generate random row column pairs for ser to guess. i = rand() % width; j = rand() % width; // Reset counting variable for each generated row column pair. correct = hints = guesses = 0; while(correct == 0 && strncmp(choice, "Q", 1) != 0){ // Count number of hints used for this specific pair. hintCount = 0; // Display message to user displaying options. printf("M[0][0]=%p. M[i][j]=%p What's i and j?\n(Q to Quit or H or HH or HHH for hints.): ", &M[0][0], &M[i][j]); // Recieve and store user input. fgets(choice, 20, stdin); // Check if user requested hints hintCount += checkHints(choice, M, width); // If user did not want hints check is valid answer submitted if (hintCount == 0){ // Check answer correct = checkAnswer(choice, i, j); } // Accumulate hints used. hints += hintCount; // Accumulate guesses used. guesses++; } // If user has not quit calculate stats for pair. if (strncmp(choice, "Q", 1) != 0){ setUnique(uniques, i, j, stats); setStats(stats,hints, guesses); } } // Print stats of the game after user has quit. printStats(stats); // terminate matrix. killMatrix(M, width); }
void TestDialog::on_btnNext_clicked() { if(siteA == true) checkAnswer(dGlobal.at(count+1)); else checkAnswer(dGlobal.at(count)); if(testCount != testSize) { testCount++; count = count+2; ui->lblCount->setText("Word: " + QString::number(testCount) + "/" + QString::number(testSize)); showQuestion(); } else { ui->btnNext->setEnabled(false); ui->edtAnswer->setEnabled(false); } }
void GamePan::nextPuzzle() { if(checkAnswer()) { Attack(_isPlayer?PLAYER_ATTACK:NPC_ATTACK); } else { Utils::openTip(TIP_SELECT_WRONG); } showHideConfirmPad(false); }
int main() { freopen("input.txt", "r", stdin); source.read(); target.read(); scanf("%lf%lf", &vMax, &tMax); windPrevSpeed.read(); windSuccSpeed.read(); double leftAnswer = 0, rightAnswer = INF; for (int binarySearchCounter = 0; binarySearchCounter <= 200; binarySearchCounter++) { double middleAnswer = (leftAnswer + rightAnswer) / 2.0; if (checkAnswer(middleAnswer)) rightAnswer = middleAnswer; else leftAnswer = middleAnswer; } printf("%.12f\n", leftAnswer); return 0; }
void GamePan::updateNpc(float delta) { string temp = DBManager::sharedDBManager()->getRandomWord(); if(checkAnswer(temp)) { Attack(NPC_ATTACK); } else { Utils::openTip(TIP_SELECT_WRONG); } //bool isAnswer = (CCRANDOM_0_1()*1000)>700; //if(isAnswer) //{ // bool isAttack = (CCRANDOM_0_1()*1000)>500; // if(isAttack) // Attack(NPC_ATTACK); // else // Utils::openTip(TIP_SELECT_WRONG); //} }
int Arith::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: generateQuestion(); break; case 1: checkAnswer(); break; case 2: losePoints(); break; default: ; } _id -= 3; } return _id; }
AddCurrencyDialog::AddCurrencyDialog(QWidget *parent, Qt::WFlags flags) : QDialog(parent, flags) { setupUi(this); progressBar->hide(); QIcon okIcon(style()->standardPixmap(QStyle::SP_DialogApplyButton)); errorIcon = style()->standardPixmap(QStyle::SP_MessageBoxCritical); warningLabel->setPixmap( okIcon.pixmap( QSize(22,22) ) ); QRegExp regexp("^0{0,1}[0-9]{1,2}$"); debetLineEdit->setValidator(new QRegExpValidator(regexp, this)); creditLineEdit->setValidator(new QRegExpValidator(regexp, this)); unknownLineEdit->setValidator(new QRegExpValidator(regexp, this)); transitLineEdit->setValidator(new QRegExpValidator(regexp, this)); QRegExp regexp1("^1{1,1}0{1,1}[0-9]{3,3}$"); numberLineEdit->setValidator(new QRegExpValidator(regexp1, this)); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect( checkBox, SIGNAL( stateChanged(int) ), this, SLOT( enableNumberLineEdit() ) ); connect( checkBox, SIGNAL( stateChanged(int) ), this, SLOT( enableOkButton() ) ); QList<QLineEdit*> list = this->findChildren<QLineEdit *>(); for(int i = 0; i < list.count(); i++) connect( list[i], SIGNAL( textChanged( const QString &) ), this, SLOT( enableOkButton() ) ); connect( okButton, SIGNAL( clicked() ), this, SLOT( okClicked() ) ); socket.setConnection( host, port, "check_if_major_currency_exists(@result)"); progressBar->show(); connect( &socket, SIGNAL( canGetData() ), this, SLOT( checkData() ) ); connect( &socket, SIGNAL( errorRaised() ), this, SLOT( loadError() ) ); connect( &qSocket, SIGNAL( canGetData() ), this, SLOT( checkAnswer() ) ); connect( &qSocket, SIGNAL( errorRaised() ), this, SLOT( loadError() ) ); }
int main(int argc, char** argv){ //--------------------Initialize Matrices, Vectors, and other Variables------------------// int N = atoi(argv[1]); int numThreads = atoi(argv[2]); struct timeval startTime, endElimination, endSubstitution; double eliminationTime, substitutionTime, totalTime; pthread_t elimination_threads[numThreads]; // Ax = b //Allocate Matrix 'A' double **A = (double **)calloc(N,sizeof(double*)); for (int q=0; q < N; q++) A[q] = (double*)calloc(N,sizeof(double*)); //Allocate Vector 'b' double* b = (double*) malloc(sizeof(double)*N); double* x = (double*) malloc(sizeof(double)*N); fillMatrix(N, A, b); //Fill in matrix A and vector B with random floating points between 0 and 1000 if (N <= 8) printf("\nPerforming gaussian elimination with the following matrix (A) and vector (b):\n\n"); printMatrix(N, A, b); //Make sure that A, b, N, and the number of threads are all global and can be shared by the different threads. thread_data.A = A; thread_data.b = b; thread_data.N = N; thread_data.numThreads = numThreads; //Create an array that can be used to pass the thread_indices to the pthread function int *index = calloc (numThreads, sizeof (int)); for(int i = 0; i < numThreads; i++) { index[i] = i; } //--------------------Perform Gaussian Elimination and Back Substituion------------------// gettimeofday(&startTime, NULL); //Gaussian Elimination for (int j=0; j < N-1; j++){ partialPivot(N, A, b, j); thread_data.j = j; for (int thread_index = 0; thread_index < numThreads; thread_index++){ pthread_create(&elimination_threads[thread_index], NULL, eliminate, (void*)&index[thread_index]); } for (int thread_index = 0; thread_index < numThreads; thread_index++){ pthread_join(elimination_threads[thread_index], NULL); } } gettimeofday(&endElimination, NULL); //Set execution time for elimination printf("\n-------Gaussian Elimination Complete-------\n"); if (N <= 8){ printf("\nPerforming back substitution with the following matrix (A) and vector (b):\n\n"); printMatrix(N,A,b); } backSubstitution(N, A, b, x, numThreads); printf("\n--------Back Substitution Complete---------\n"); gettimeofday(&endSubstitution, NULL); //Set execution time for substitution //---------------------------Calculate Run Times and print out Solutions---------------------------------// eliminationTime = ((endElimination.tv_sec - startTime.tv_sec) * 1000000u + endElimination.tv_usec - startTime.tv_usec) / 1.e6; substitutionTime = ((endSubstitution.tv_sec - endElimination.tv_sec) * 1000000u + endSubstitution.tv_usec - endElimination.tv_usec) / 1.e6; totalTime = ((endSubstitution.tv_sec - startTime.tv_sec) * 1000000u + endSubstitution.tv_usec - startTime.tv_usec) / 1.e6; printSolutionVector(x, N); checkAnswer(A,x,b,N); printf("Substitution execution time: %.3f seconds.\n", eliminationTime); printf("Substitution execution time: %.3f seconds.\n", substitutionTime); printf("Total execution: \n%.3f seconds elapsed with %d threads used.\n\n", totalTime, numThreads); }
void AddRuleDialog::loadEnv() { socket = new QuerySocket(this); connect( socket, SIGNAL( errorRaised() ), this, SLOT( loadError() ) ); connect( socket, SIGNAL( canGetData() ), this, SLOT( checkAnswer() ) ); }
void boxAsker::keyReleaseEvent(QKeyEvent *e) { if (e -> key() == Qt::Key_Return || e -> key() == Qt::Key_Enter) checkAnswer(); else askWidget::keyReleaseEvent(e); }
int main(int args, char *argv[]) { int isOnline = 1; struct hostent* he; struct sockaddr_in server; int sock_fd; int playerAnswer; int quesReceived = 0; int choice, i; int help_choice[HELP_CHOICES]; int clientId = UNDEFINED; char clientName[40]; char c; Question ques; StatusType clientStatus; MainPlayerData toPlayerData; CandidateData toCandidateData; createCashPrizeList(); if (args != 3) { printf("Usage : %s <IP> <PORT>\n", argv[0]); exit(-1); } if ((he = gethostbyname(argv[1])) == NULL ) { printf("Cannot get the server !\n"); exit(-1); } server.sin_family = AF_INET; server.sin_port = htons(atoi(argv[2])); server.sin_addr = *((struct in_addr*) he->h_addr); bzero(&(server.sin_zero), 8); // create a socket to server if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { printf("Cannot create a socket !\n"); exit(-1); } if (connect(sock_fd, (struct sockaddr*) &server, sizeof(struct sockaddr)) == -1) { printf("error connect"); exit(1); } recv(sock_fd, &clientId, sizeof clientId, 0); if (clientId == NULL_ID) { printf(CLIENT_FULL_MESSAGE); close(sock_fd); exit(-1); } //printf("Get the id : %d\n", clientId); printf("=====WELCOME TO THE WHO WANT TO BE A MILLIONAIRE\n"); printf("Enter your name : "); //get the user name gets(clientName); toCandidateData.status = CONNECTED; //send the data to server to let server know you name send(sock_fd, &toCandidateData, sizeof toCandidateData, 0); send(sock_fd, clientName, sizeof clientName, 0); // get the data back then display message for the first time join to game (this time a welcome message) recv(sock_fd, &toCandidateData, sizeof toCandidateData, 0); displayCandidateMessage(toCandidateData); clientStatus = toCandidateData.status; // print the client's status // printf("The client %d has status : ", clientId); // toString(clientStatus); //playerAnswer = RIGHT; /*handle data sent from server according to client role */ while (isOnline) { switch (clientStatus) { case WAITING: recv(sock_fd, &toCandidateData, sizeof toCandidateData, 0); clientStatus = toCandidateData.status; if (clientStatus == WAITING) { displayCandidateMessage(toCandidateData); } copyQuestion(&ques, toCandidateData.question); break; case COMPETING: //displayCandidateMessage(toCandidateData); //displayQuestion(ques); compete(&toCandidateData, ques); printf("Waiting for result....!\n"); sleep(1); //fflush(stdout); //endwin(); // send answer to server // send(sock_fd, &toCandidateData, sizeof toCandidateData, 0); //receive the result and change the status of client according to result recv(sock_fd, &toCandidateData, sizeof toCandidateData, 0); displayAnswer(ques); sleep(1); displayCandidateMessage(toCandidateData); clientStatus = toCandidateData.status; // printf("The client %d has status : ", clientId); // toString(clientStatus); //fflush(stdout); // return 0; // exit(0); break; case JOINING: ques = toPlayerData.ques; recv(sock_fd, &toPlayerData, sizeof toPlayerData, 0); if (quesReceived == 1) { displayAnswer(ques); } sleep(1); if (toPlayerData.status == FINISHED) { displayPlayerMessage(toPlayerData); exit(1); } broadTheGame(toPlayerData); quesReceived = 1; break; case PLAYING: //fflush(stdout); for (i = 0; i < HELP_CHOICES; i++) { help_choice[i] = AVAILABLE; } do { while (getchar() != '\n') ; recv(sock_fd, &toPlayerData, sizeof toPlayerData, 0); if (toPlayerData.status == FINISHED) { displayPlayerMessage(toPlayerData); exit(1); } sleep(1); displayPlayerMessage(toPlayerData); sleep(1); broadTheGame(toPlayerData); printf( "\n>>Your choice (press 'H' to get help or 'L' to leave the game): "); c = getchar(); choice = handleAnswer(c); //if the player has his own answer while (1) { if (choice != HELP_MODE) {//neu nguoi choi ko chon tro giup playerAnswer = checkAnswer(choice, toPlayerData.ques.ans); send(sock_fd, &playerAnswer, sizeof playerAnswer, 0); break; } //else if he needs help else { //xu ly tro giup helpMenu(&toPlayerData, help_choice); printf( "\n>>Your choice (press 'H' to get help or 'L' to leave the game): "); while (getchar() != '\n') ; c = getchar(); choice = handleAnswer(c); } } } while (playerAnswer == RIGHT); if (playerAnswer == WRONG || playerAnswer == END) { recv(sock_fd, &toPlayerData, sizeof toPlayerData, 0); sleep(1); displayAnswer(toPlayerData.ques); displayPlayerMessage(toPlayerData); isOnline = 0; clientStatus = FINISHED; close(sock_fd); exit(-1); } //fflush(stdout); break; default: printf("We will handle soon ...\n"); break; } //fflush(stdout); } return 0; }