0

i don't have a clue what is wrong here....
the program is supposed to add, subtract, multiply and divide two real numbers.

#include<stdio.h>

float add(float x, float y);
float subtract(float x, float y);
float multiply(float x, float y);
float divide(float x, float y);

int main (void)
{

int choice;
float x, y;

while(1)
{
    printf("\nPress 1 to add two  numbers.\n");
    printf("Press 2 to subtract two numbers.\n");
    printf("Press 3 to multiply two numbers.\n");
    printf("Press 4 to divide two numbers.\n");
    printf("Press 5 to exit the program.\n");
    printf("\nEnter your choice:\n");
    scanf("%d",&choice);

    if(choice==5)
    {
        return 0;
    }

    if(choice >= 1 && choice <= 4)

    {
    printf("Please enter a real number:\n");
    scanf("%f", &x);

    printf("Please enter another real number:\n");
    scanf("%f", &y);

    if (choice==1)
    {    
    printf("The sum of both values inputted: % f\n", add(x, y));
    }

    float add(float x, float y)

    {
        return x+y;
    }

    else if (choice==2)
    {    
    printf("The difference of both values inputted: % f\n", subtract(x, y));
    }

    float subtract(float x, float y)

    {
        return x-y;
    }


    else if (choice==3)
        {    
    printf("The difference of both values inputted: % f\n", multiply(x, y));
    }

    float multiply(float x, float y)

    {
        return x*y;
    }

    else if (choice==4)
    {    
    printf("The difference of both values inputted: % f\n", divide(x, y));
    scanf("%f",x/y)
    }

    float divide(float x, float y)

    {
        return x/y;
    }


}
}
3
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by CGSMCMLXXV
0

Few problems here:

  1. Function definition inside another function (take all the function definitions outside the main function scope).
  2. Missing } (you open 4 curly brackets for: main, while, if, if and you close only 3 curly brackets).
  3. Missing ; after scanf (line 75)
  4. Is there any reason at all for that scanf (line 75)?

That to ignore the warning coming from scanf.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.