#include <math.h>
#include <stdio.h>
/*float addisjon (float num1, float num2); This part is to looked past, I think it does nothing.
float subtraksjon (float num1, float num2);
float multiplikasjon (float num1, float num2);
float divisjon (float num1, float num2);
*/
void setup() {
Serial.begin(57600);
Serial.println("Welcome to the Arduino based calculator. Select the operator.");
Serial.println("1) Addition");//To variabler og en operator - Simple addition with two variables and an operator
Serial.println("2) Substraction");//To variabler og en operator - Simple subtraction with two variables and an operator
Serial.println("3) Multiplication");//To variabler og en operator - Simple multiplication with two variables and an operator
Serial.println("4) Division");//To variabler og en operator - Simple division with two variables and an operator
}
int lesAvPC() {
while (Serial.available() == 0);
return Serial.parseInt();
}
void loop() {
switch (lesAvPC())
{
case 1:
{
Serial.print("1) Write first numbers: ");
float num1 = lesAvPC();
Serial.println(num1);
Serial.println(" Operator uses: +");
Serial.print(" Write second numbers: ");
float num2 = lesAvPC();
Serial.println(num2);
Serial.println(" ");
Serial.print(" The answer is: ");
float fasit = num1 + num2; Would like all the first 4 cases to be one case which includes all operators
Serial.println(fasit); //answer
Serial.println(" ");
// Serial.print("(num1 + num2) = (fasit())");
Serial.println("........................................");
break;
}
case 2:
{
Serial.print("2) Write the first numbers: ");
float num1 = lesAvPC();
Serial.println(num1);
Serial.println(" Operator uses: -");
Serial.print(" Write the second numbers: ");
float num2 = lesAvPC();
Serial.println(num2);
Serial.println(" ");
Serial.print(" The answer is: ");
float fasit = num1 - num2;
Serial.println(fasit);
Serial.println(" ");
// Serial.print("(num1 - num2) = (fasit())");
Serial.println("........................................");
break;
}
case 3:
{
Serial.print("3) Write the first numbers: ");
float num1 = lesAvPC();
Serial.println(num1);
Serial.println(" Operator uses: *");
Serial.print(" Write the second numbers: ");
float num2 = lesAvPC();
Serial.println(num2);
Serial.println(" ");
Serial.print(" The answer is: ");
float fasit = num1 * num2;
Serial.println(fasit);
Serial.println(" ");
// Serial.print("(num1 * num2) = (fasit())");
Serial.println("........................................");
break;
}
case 4:
{
Serial.print("4) Write the first numbers: ");
float num1 = lesAvPC();
Serial.println(num1);
Serial.println(" Operator uses: /");
Serial.print(" Write the second numbers: ");
float num2 = lesAvPC();
Serial.println(num2);
Serial.println(" ");
Serial.print(" The answer is: ");
float fasit = num1 / num2;
Serial.println(fasit);
Serial.println(" ");
// Serial.print("(num1 / num2) = (fasit())");
Serial.println("........................................");
break;
}
}