Skip to main content
deleted 116 characters in body
Source Link
Ishaan
  • 474
  • 1
  • 3
  • 13
  • You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

voidfloat addition(){

    float num1, num2;
    float result;
    
    printf("Enter first number: "num2);{
       
    return num1 scanf("%f",+ &num1);num2;
}
            printf("Enter second number: "); 
            scanf("%f", &num2);//or

void addition(float num1, float printf("\n"num2);{
    
    float result = num1 + num2;
    
    printf("%.2f + %.2f = %"%0.2f\n", num1, num22f", result);

}

This wayIn the second example, you also create and destroy num1 num2 and result each function call.

  • Consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • You don't need multiple printf statements for the menu options. Simply continuing as such is needed:

    printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n\n");

  • You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

void addition(){

    float num1, num2;
    float result;
    
    printf("Enter first number: ");
            scanf("%f", &num1);

            printf("Enter second number: "); 
            scanf("%f", &num2);

    printf("\n");
    
    result = num1 + num2;
    
    printf("%.2f + %.2f = %.2f\n", num1, num2, result);

}

This way, you also create and destroy num1 num2 and result each function call.

  • Consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • You don't need multiple printf statements for the menu options. Simply continuing as such is needed:

    printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n\n");

  • You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

float addition(float num1, float num2){
 
    return num1 + num2;
}

//or

void addition(float num1, float num2){

    float result = num1 + num2;
    printf("%0.2f", result);

}

In the second example, you create and destroy result each function call.

  • Consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • You don't need multiple printf statements for the menu options. Simply continuing as such is needed:

    printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n\n");

added 221 characters in body
Source Link
Ishaan
  • 474
  • 1
  • 3
  • 13

You should really consider making functions for each mathematical operation and keep the main() simple.

  • You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

void addition(){

    float num1, num2;
    float result;
    
    printf("Enter first number: ");
            scanf("%f", &num1);

            printf("Enter second number: "); 
            scanf("%f", &num2);

    printf("\n");
    
    result = num1 + num2;
    
    printf("%.2f + %.2f = %.2f\n", num1, num2, result);

}

This way, you also create and destroy num1 num2 and result each function call.

Also consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • Consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • You don't need multiple printf statements for the menu options. Simply continuing as such is needed:

    printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n\n");

You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

void addition(){

    float num1, num2;
    float result;
    
    printf("Enter first number: ");
            scanf("%f", &num1);

            printf("Enter second number: "); 
            scanf("%f", &num2);

    printf("\n");
    
    result = num1 + num2;
    
    printf("%.2f + %.2f = %.2f\n", num1, num2, result);

}

This way, you also create and destroy num1 num2 and result each function call.

Also consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

void addition(){

    float num1, num2;
    float result;
    
    printf("Enter first number: ");
            scanf("%f", &num1);

            printf("Enter second number: "); 
            scanf("%f", &num2);

    printf("\n");
    
    result = num1 + num2;
    
    printf("%.2f + %.2f = %.2f\n", num1, num2, result);

}

This way, you also create and destroy num1 num2 and result each function call.

  • Consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.

  • You don't need multiple printf statements for the menu options. Simply continuing as such is needed:

    printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n\n");

Source Link
Ishaan
  • 474
  • 1
  • 3
  • 13

You should really consider making functions for each mathematical operation and keep the main() simple.

As an example:

void addition(){

    float num1, num2;
    float result;
    
    printf("Enter first number: ");
            scanf("%f", &num1);

            printf("Enter second number: "); 
            scanf("%f", &num2);

    printf("\n");
    
    result = num1 + num2;
    
    printf("%.2f + %.2f = %.2f\n", num1, num2, result);

}

This way, you also create and destroy num1 num2 and result each function call.

Also consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.