We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,231 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problem with Menu Program

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
23 Minutes
Discussion Span
4 Months Ago
Last Updated
3
Views
ThatBitchYeah
Newbie Poster
18 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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?

Ancient Dragon
Achieved Level 70
Team Colleague
32,137 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,576
Skill Endorsements: 69

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.

CGSMCMLXXV
Junior Poster in Training
54 posts since Jan 2013
Reputation Points: 5
Solved Threads: 7
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0620 seconds using 2.69MB