Interactive Alarm Clock Code

Dependencies:   4DGL-uLCD-SE mbed

mathProblem.cpp

Committer:
tshin7
Date:
2015-12-10
Revision:
0:68a3851de2ee

File content as of revision 0:68a3851de2ee:

#include "mbed.h"
#include "uLCD_4DGL.h"
#include "mathProblem.h"
#include <string>

uLCD_4DGL math(p9,p10,p11); // serial tx, serial rx, reset pin;
int ranNum1;
int ranNum2;
int ranNum3;
int answer;
int operationChoice;

int mathProblem::displayMathProblem()
{
    math.locate(0,14);
    math.printf("Math Problem:");
    
    operationChoice = rand()%3;
    
    if (operationChoice == 0) {
        ranNum1=rand()%9+1;
        ranNum2=rand()%9+1;
        ranNum3=rand()%9+1;
        
        answer = ranNum1 + ranNum2 * ranNum3;
        
        math.locate(0,15);
        math.printf("%d + %d * %d = ???",ranNum1, ranNum2, ranNum3);
    } else if (operationChoice == 1) {
        ranNum1=rand()%9+1;
        ranNum2=rand()%9+1;
        ranNum3=rand()%9+1;
        
        answer = ranNum1 - ranNum2 * ranNum3;
        
        math.locate(0,15);
        math.printf("%d - %d * %d = ???",ranNum1, ranNum2, ranNum3);
    } else if (operationChoice == 2) {
        ranNum1=rand()%9+1;
        ranNum2=rand()%9+1;
        ranNum3=rand()%9+1;
        
        answer = ranNum1 * ranNum2 * ranNum3;
        
        math.locate(0,15);
        math.printf("%d * %d * %d = ???",ranNum1, ranNum2, ranNum3);
    }
    return answer;
}

void mathProblem::eraseMathProblem()
{
    
    math.locate(0,14);
    math.printf("             ");
    math.locate(0,15);
    math.printf("                  ");
}