Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
#include <time.h>
#include <stdlib.h>
#define SIZE 10
//time function
void time (int timer) {
if(timeLeft < 0)
{
// timer has finished
break;
}
}
}
//Operation function
double do_operation(int operator1, int value1, int value2) {
if (operator1 == '+') { return value1 + value2; }
if (operator1 == '-') { return value1 - value2; }
if (operator1 == '*') { return value1 * value2; }
return value1 / value2;
}
Value1++;
Value2++;
Operator++;
}
timer=140;
time (int timer)
}
if (choice == 2){
{ srand(time(0)); //seed random number generator
int value1 = rand() % 14 + 1; // random number between 1 and 14
int value2 = rand() % 14 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=130;
time (int timer)
}
if (choice == 3) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 18 + 1; // random number between 1 and 18
int value2 = rand() % 18 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=120;
time (int timer)
}
if (choice == 4) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 22 + 1; // random number between 1 and 18
int value2 = rand() % 22 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=110;
time (int timer)
}
if (choice == 5) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 26 + 1; // random number between 1 and 18
int value2 = rand() % 26 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=100;
time (int timer)
}
if (choice == 6) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 30 + 1; // random number between 1 and 18
int value2 = rand() % 30 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=90;
time (int timer)
}
if (choice == 7) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 34 + 1; // random number between 1 and 18
int value2 = rand() % 34 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);}
Value1++;
Value2++;
Operator++;
}
timer=80;
time (int timer)
}
if (choice == 8) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 38 + 1; // random number between 1 and 18
int value2 = rand() % 38 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=70;
time (int timer)
}
if (choice == 9) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 42 + 1; // random number between 1 and 18
int value2 = rand() % 42 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Printf (“%d %c %d”, value1, operator1, value2);
Value1++;
Value2++;
Operator++;
}
timer=60;
time (int timer)
}
if (choice == 10) {
{ srand(time(0)); //seed random number generator
int value1 = rand() % 46 + 1; // random number between 1 and 18
int value2 = rand() % 46 + 1;
char operator1 = get_operator(rand() % 4);
double answer = do_operation(operator1, value1, value2);
Value1++;
Value2++;
Operator++;
}
timer=50;
time (int timer)
}
//Answering loop
while (tries > 0 && !solved)
{
solved = true;
}
else // wrong answer
{
wrong++;
tries--;
if (tries > 0)
{solved = true;
playing = false;
printf (“The correct answer was: %d”, answer);}
}
}
}
q--; // decrease q by one to hold actual number of passed questions
correct += correct;
wrong += wrong;
stats(); }
//Get input:
scanf (“%d”, int &choice);
if (choice ==11) {break;}
else if (choice>11) {printf (“Incorrect input. Choose one of the visible choices”}
else if (choice>=’A|| choice<=’Z’ ||choice>=’a’ ||choice ‘z’) (“Incorrect input. Choose
one of the visible choices”}
//Cases:
if (choice == 1) test(stage1);
if (choice == 2) test(stage2);
if (choice == 3) test(stage3);
if (choice == 4) test (stage4);
if (choice == 5) test (stage5);
if (choice == 6) test (stage6);
if (choice == 7) test(stage7);
if (choice == 8) test(stage8);
if (choice == 9) test(stage9);
if (choice == 10) test (stage10);
}
return 0;
}