All pastes #338785 Raw Edit

Something

public cpp v1 · immutable
·published 2007-02-03 18:18 UTC
rendered paste body
#include <cstdlib>#include <iomanip>using std::setw;#include <iostream>using std::cin;using std::cout;using std::endl;#include <string>using std::string;#include <boost/timer.hpp>using boost::timer;int pow(int x,int n);int main(int argc, char *argv[]){    unsigned int nDigits1, nDigits2;    char opType;    int num1, num2;    int ans;    int res;    double t1;    timer tim;    tim.restart();    srand(time(0)); // initialize random number generator    cout << "Welcome to Mentat: the mental math practice.\n\n";    cout << "Choose one of the following operators: +,-,*,/: ";    cin >> opType;    if ( opType != '+' && opType !='-' && opType != '*' && opType != '/')        return 0;    cout << endl;    cout << "Choose the number of digits: \n";    cout << "No. 1: ";    cin >> nDigits1;    cout << "No. 2: ";    cin >> nDigits2;    cout << endl;    if ( opType == '/' && nDigits2 > nDigits1)        return 0;    num2 = (rand() % pow(10,nDigits2)) + 1;     do  num1 = (rand() % pow(10,nDigits1) +1);    while ( num1 < num2 && opType == '/' && num1 % num2 != 0);            cout << "Question:" << num1 << " " << opType  << " " << num2  << " ="<< endl ;    cout << "Answer: " ;    cin >> ans;    t1 = tim.elapsed();    cout << t1;     cout << endl;    switch (opType)    {        case '+':            res = num1 + num2;            break;        case '-':            res = num1 - num2;            break;        case '*':            res = num1 * num2;            break;        case '/':            res = num1 / num2;    }    if (res == ans)        cout << "Correct!\n";    else        cout << "Wrong!!\n";    return 0;}int pow(int x,int n){    int res = 1;    for (int i = 0; i < n; ++i)        res *= x;      return res;}