1,105,288 Community Members

Problem with Menu Program

Member Avatar
ThatBitchYeah
Newbie Poster
18 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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;
    }


}
}
Member Avatar
Ancient Dragon
Achieved Level 70
27,577 posts since Aug 2005
Reputation Points: 5,231 [?]
Q&As Helped to Solve: 3,028 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

what doesn't it do that you want it to do? Or what does it do that you don't want it to do?

Member Avatar
CGSMCMLXXV
Junior Poster in Training
54 posts since Jan 2013
Reputation Points: 5 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article