123456789101112

#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;
  }

}

Hello,

do you have an installation question?

Do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

My guess is English is not your native language. Which is OK but you have to tell us if that is the case.
And, if you need some help you must give us a description of what your issue is.

Whether on purpose or not, the only thing you did was post some code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.