Advertisement
gabbyshimoni

SimpleCalculator

Feb 7th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. void setup() {
  2.   Serial.begin(9600);
  3. }
  4.  
  5. void loop() {
  6.   // put your main code here, to run repeatedly:
  7.   Serial.println("enter targil:");
  8.   while (Serial.available() == 0);
  9.   int a = Serial.parseInt();
  10.   char ch = Serial.read();
  11.   int b = Serial.parseInt();
  12.   if (ch == '+') {
  13.     Serial.print(a);
  14.     Serial.print(ch);
  15.     Serial.print(b);
  16.     Serial.print("=");
  17.     Serial.println(a + b);
  18.   }
  19.   if (ch == '-') {
  20.     Serial.print(a);
  21.     Serial.print(ch);
  22.     Serial.print(b);
  23.     Serial.print("=");
  24.     Serial.println(a - b);
  25.   }
  26.   if (ch == '*') {
  27.     Serial.print(a);
  28.     Serial.print(ch);
  29.     Serial.print(b);
  30.     Serial.print("=");
  31.     Serial.println(a * b);
  32.   }
  33.   if (ch == '/') {
  34.     Serial.print(a);
  35.     Serial.print(ch);
  36.     Serial.print(b);
  37.     Serial.print("=");
  38.     Serial.println(a / b);
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement