I am just a beginner i am stuck with getting my if statements working, they both execute, i know their are better way to write the programme , but i would like to know what do i have to change to make it work, i think i am getting confused on strings and char.
any help would be appreciated.
#include <LiquidCrystal.h>
#include <String.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
int num1;
int num2;
char choice;
int add;
int subtract;
int answer;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16,2);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,0);
Serial.println("enter a number 1");
lcd.println("enter num 1");
delay(2000);
while (Serial.available()==0){
}
num1=Serial.parseInt();
lcd.setCursor(0,1);
lcd.print(num1);
Serial.println(" Enter number 2");
while (Serial.available()==0){
}
num2=Serial.parseInt();
lcd.setCursor(3,1);
lcd.print(num2);
Serial.println("Do you want to add,subtract,divide,multiply");
while (Serial.available()==0){
}
choice=Serial.parseInt();
if (strcmp(choice,add)==0){
lcd.setCursor(1,1);
lcd.print("+");
answer=(num1+num2);
lcd.setCursor(5,1);
lcd.print(answer);
lcd.setCursor(4,1);
lcd.print("=");
delay(5000);
}
if (strcmp(choice,subtract)==0){
lcd.setCursor(1,1);
lcd.print("-");
answer=(num1-num2);
lcd.setCursor(5,1);
lcd.print(answer);
delay(5000);
}
}
type or paste code here