Keypad

We're making an alarm clock using arduino uno. This alarm clock displays arithmetic problem once the alarm goes on. And as the user input the correct answer using the 4x4 keypad, the alarm goes off.
Our clock already displays the time and math problem as the alarm goes on. We're only having a problem with the keypad. It's not working with our code. We can't input the correct answer.
Here's our code. Please someone help us. Thank you.

#include "Time.h"
#include "TimeAlarms.h"
#include <Wire.h>
#include "Keypad.h"
#include <LiquidCrystal.h>


LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);

int mathValOne = 0;
int mathValTwo = 0;
int mathValThree = 0;
int realAnswer = 0;
const int Buzzer = 9;
int toneOn = 0;
long previousMillis = 0;
int x = 0;
long interval = 70;
long interval2 = 500;

const byte ROWS = 4; 
const byte COLS = 4; 

char keys[ROWS][COLS] = 

 {

  
 {'7','8','9','/'},

  
 {'4','5','6','X'},

  
 {'1','2','3','-'},

  
 {'#','0','=','+'}

 };

 byte rowPins[ROWS] = { 3, 4, 5, 2 };
 byte colPins[COLS] = { 6, 7, 8, 9 }; 



 Keypad kpd = Keypad( makeKeymap(keys), rowPins,
 colPins, ROWS, COLS );

 void setup() 

 {
 
 lcd.begin(16, 2);

 setTime(20, 34, 0, 10, 07, 16); 

 Alarm.alarmRepeat(20, 35, 0, Alaarm);

 Wire.begin();

 pinMode(Buzzer, OUTPUT);

 }

void BuzzerOn() {
 NOISE();
MathProblem();
}

void BuzzerOff() {
 noTone(9);
 delay(500);
 Clock();
}

void NOISE() {
 
 unsigned long currentMillis = millis();
 if (currentMillis - previousMillis > interval && x < 8) {
   previousMillis = currentMillis;
   if (toneOn == 0) {
     toneOn = 2048;

   }
   else
     toneOn = 0;
   tone(9, toneOn);
   if (toneOn == 0)
     noTone(9);
   x++;
 }
 if (currentMillis - previousMillis > interval2 && x == 8) {
   previousMillis = currentMillis;
   noTone(9);
   x = 0;
 }
}

void Clock() {
 lcd.setCursor(0,0);
 lcd.print(hour());
 printDigits(minute());
 printDigits(second());
 lcd.println("              ");
}

void printDigits(int digits) {
 lcd.print(":");
 if (digits < 10)
   lcd.print('0');
 lcd.print(digits);
}

 void loop() 
 {

 lcd.setCursor(0, 0);
 Clock();
 Alarm.delay(1000); // wait one second between clock display
 // Turn off the display:
 lcd.noDisplay();
 // Turn on the display:
 lcd.display();

 }

 void Alaarm() {
 BuzzerOn();
}

void MathProblem() {
     mathValOne = random(11, 17);
     mathValTwo = random(7, 10);
     mathValThree = random(20, 80);
     realAnswer = mathValOne * mathValTwo + mathValThree;
     delay(500);
     lcd.setCursor(0, 1);
     lcd.print(mathValOne);
     lcd.print("*");
     lcd.print(mathValTwo);
     lcd.print("+");
     lcd.print(mathValThree);
     lcd.print(" = ");
     char key
 = kpd.getKey();

  
 if(key)  

   {
     lcd.print(key);
     delay(100);
    }
     if (realAnswer != key) {
       MathProblem();
   }
   if (realAnswer == key) {
      BuzzerOff();
     delay(500);
   }
}

Please use code tags. Use the </> icon in the posting menu. [code] Paste sketch here. [/code]

[quote author=jajajaoda link=msg=2972684 date=1477271785]
     char key
 = kpd.getKey();
[/quote]
You are reading only one character at a time. There is nothing wrong with that (it is the normal way of doing things), but there is something wrong with what follows.
[quote]  
 if(key)  

   {
     lcd.print(key);
     delay(100);
    }
     if (realAnswer != key) {
       MathProblem();
   }
   if (realAnswer == key) {
      BuzzerOff();
     delay(500);
   }
}

[/quote]
There are two serious mistakes here.
The first mistake is confusion of the characters '0' through '9' with the mathematical numbers zero through nine. The Arduino treats the character '1' differently from the number one.
The second mistake is that, as soon as a key is pressed, you decide whether the answer is correct or not. If the correct answer is 123 and I press the 1 key, have I given the wrong answer? You should wait for me to input the other two digits before calling my answer right or wrong.

Here is a thread about a problem similar to yours. I suggest you read it and try to learn from it. Please read the entire thread, as it contains mistakes as well as corrections for those mistakes.
https://forum.arduino.cc/index.php?topic=57627.0