This is the code to the math game mini project.

Dependencies:   4DGL-uLCD-SE mbed

Files at this revision

API Documentation at this revision

Comitter:
rjuste3
Date:
Fri Mar 13 14:33:54 2015 +0000
Parent:
0:aedab05ce6cc
Commit message:
Mini project

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r aedab05ce6cc -r 03c9bef920a6 main.cpp
--- a/main.cpp	Fri Mar 13 13:52:29 2015 +0000
+++ b/main.cpp	Fri Mar 13 14:33:54 2015 +0000
@@ -22,10 +22,12 @@
 
 
 void generateProblem(){
+    //generates random numbers between 1 and 40 as operands
     operand1 = rand() % 40 + 1;
     operand2 = rand() % 40 + 1;
     op = rand() % 3;
     
+    //genearte random operator and appropriate answer
     if (op == 0){
         uLCD.locate(0,0);
         uLCD.printf("%d + %d\n",operand1, operand2);
@@ -56,7 +58,7 @@
 
     bool randomGen = true;
     t.start();
-    while(randomGen){
+    while(randomGen){ //push any button to start game
         uLCD.locate(1,0);
         uLCD.printf("Push any button to start the game");
         if(pb1==0 || pb2==0 || pb3==0 || pb4==0 || pb5==0 || pb6 == 0){
@@ -74,19 +76,20 @@
     
     
    while(true){
-    generateProblem();
+    generateProblem(); //generate problem
     uLCD.locate(1,14);
-    uLCD.printf("Score: %d",score);
+    uLCD.printf("Score: %d",score);//display score
     t.start();
     
     while(t.read() <= seconds){
-           if(seconds - (int)t.read() < 10){
+           if(seconds - (int)t.read() < 10){ //display time limit
                uLCD.locate(13,1);
                uLCD.printf("%d",(seconds -(int)t.read()));
                } else{
            uLCD.locate(12,1);
            uLCD.printf("%d",(seconds -(int)t.read()));
            }
+           //push pushbutton to add up your answer to approach correct answer
        if(pb1 == 0)
         {
         ans = ans + 1;
@@ -131,7 +134,7 @@
         }
       }
       
-      if( ans == answer){
+      if( ans == answer){//if correct answer then add score and decrease time limit
         score += 1;
         seconds -=3;
         }else