Connect with us

Min-Max Code Problem.

Discussion in 'Microcontrollers, Programming and IoT' started by [email protected], Nov 24, 2011.

  1. Richard@EELTD

    [email protected]

    4
    0
    Apr 1, 2011
    I've been working on a code to take the max and min of 11 user inputted numbers, but I can't get the code to work.

    I was wondering if anyone here could help me troubleshoot the code :)


    #include <stdio.h>
    int max, min;
    int a,b,c,d,e,f,g,h,i,j,k;
    MAXMIN(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int min, int max)
    {
    min=(std::min a,b,c,d,e,f,g,h,i,j,k);
    max=(std::max a,b,c,d,e,f,g,h,i,j,k);
    }
    main()
    {
    int a,b,c,d,e,f,g,h,i,j,k;
    int min, max;
    printf ("Enter an integer number.\n");
    scanf("%d",&a);
    printf ("Enter a second integer number.\n");
    scanf("%d",&b);
    printf ("Enter a third integer number.\n");
    scanf("%d",&c);
    printf ("Enter a fourth integer number.\n");
    scanf("%d",&d);
    printf ("Enter a fifth integer number.\n");
    scanf("%d",&e);
    printf ("Enter a sixth integer number.\n");
    scanf("%d",&f);
    printf ("Enter a seventh integer number.\n");
    scanf("%d",&g);
    printf ("Enter an eighth integer number.\n");
    scanf("%d",&h);
    printf ("Enter a ninth integer number.\n");
    scanf("%d",&i);
    printf ("Enter a tenth integer number.\n");
    scanf("%d",&j);
    printf ("Enter a eleventh integer number.\n");
    scanf("%d",&k);
    min=0;
    max=0;
    MAXMIN(a,b,c,d,e,f,g,h,i,j,k,&min,&max);
    printf("The minimum of your inputted numbers is "%d"\n",&min);
    printf("The maximum of your inputter numbers is "%d"\n",&max);
    }




    Thanks in advance.
     
  2. daddles

    daddles

    443
    3
    Jun 10, 2011
    Please use CODE tags for your code. Most programmers hate to look at flat code.

    You also don't say what language or compiler you're using. It looks like it might be C or C++; however, your code won't compile with either compiler. I suggest never posting code that can't compile (unless your problem is that you can't figure out why it won't compile).

    I see lots of errors in your code, so first focus on posting something that compiles and demonstrates the error you're getting. Also state what compiler you're using along with examples of the input you gave and the output you got. If you're not willing to go to this trouble, you'll find fewer people who are willing to respond, at least in my experience.

    Finally, you need to learn how to reduce your problem to its essence. In this case, it means removing all the fluff that's not needed to exhibit the problem. That would mean to e.g. start with only gathering two or three numbers first. That cuts the number of lines down by roughly a half.
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,175
    2,690
    Jan 21, 2010
    In this case an additional useful thing would be an image (or some other log) of the program running showing the numbers being entered and the result being printed.

    You should compare the way you call your maxmin routine with how you define it.

    Some compilers would give errors, some warnings, and others would silently let you do it. I'm wondering what you have?
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-