Thread: Unlimited Inputs and Determines which is greatest and lowest

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Post #7 has a solution, and if you combine that with post #8, you would have a "simpler" solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    Code:
    int w,x,y,ans;
    printf("Enter a number: ");
    scanf("%d",&x);
    do{
    for(y=1;y<=x;y++){
    printf("Input number: ");
    scanf("%d",&w);
    if(w>y)
    ans=w;
    	}
    		}
    while(y<=x);
    printf("The highest number is %d.\n",ans);

    just a little bit more T_T


    help please

  3. #18
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Code:
     
    BOOL isFirst;
    DWORD Biggest;
    DWORD Smallest;
     
    // get number of values N
     
    isFirst = TRUE;
    for(i=0;i<N;i++){
        //get the input value V
        if(isFirst){
            Biggest = V;
            Smallest = V;
            isFirst = FALSE;
            } else {
            Biggest = __max(V , Biggest);
            Smallest = __min(V , Smallest);
            }
        }
     
    // print out the biggest and smallest value

  4. #19
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    waaaaaaaaaaaaaaaaaa


    i cant understand T_T

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by abachler View Post
    Code:
     
    BOOL isFirst;
    DWORD Biggest;
    DWORD Smallest;
     
    // get number of values N
     
    isFirst = TRUE;
    for(i=0;i<N;i++){
        //get the input value V
        if(isFirst){
            Biggest = V;
            Smallest = V;
            isFirst = FALSE;
        } else {
            Biggest = __max(V , Biggest);
            Smallest = __min(V , Smallest);
        }
    }
     
    // print out the biggest and smallest value
    Code:
    if (x) {
        }
    Is never a good coding style...

    omarbags:
    If you can't understand such simple code, then programming may not be for you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i cant understand T_T
    What part do you have trouble understanding?

    Is never a good coding style...
    In this case isFirst is clearly a boolean variable, and the variable is named isFirst, not something with so little context as x.

    If you can't understand such simple code, then programming may not be for you.
    To be fair, abachler's code example uses type and function names found in a library that is not part of standard C.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by laserlight View Post
    In this case isFirst is clearly a boolean variable, and the variable is named isFirst, not something with so little context as x.
    I was on about bracket placement...

    To be fair, abachler's code example uses type and function names found in a library that is not part of standard C.
    Perhaps. Perhaps not. Let's reserve judgment, then, until later.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Elysia View Post
    Code:
    if (x) {
        }
    Is never a good coding style...
    (snipped for social acceptability of the post) I use K&R style and if you dont like it take it up with them.

    here, prepend this then and it will work fine

    Code:
    #define BOOL int
    #define DWORD unsigned int
    that is after all, exactly what VC++ does.
    Last edited by abachler; 02-08-2008 at 11:02 AM.

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by abachler View Post
    (snipped for social acceptability of the post) I use K&R style and if you dont like it take it up with them.
    No,
    Code:
    if (x) {
    }
    Is fine. K&R style.
    Code:
    if (x) {
    	}
    Is not fine. Not K&R style.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    It could be some kind of hybrid K&R and Allman, I suppose. An indenting style doesn't necessarily have to be one of the standard ones (I use a modified K&R where I indent functions the same as everything else).

    Edit: Sorry, substitute Whitesmiths for Allman.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, coding styles are something that you should make up yourself. However, there are still guidelines to follow or you'll make it confusing.
    The least confusing style IMO is Allman. Then K&R, then the rest.
    Nevertheless, that hybrid style is not a good one. Brackets should be at the same level, otherwise it's confusing to the reader.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    is the program working?

    i hope someone could give me a simplified program

    im really slow in C programming and i am learning it here...

    thanks a lot to everyone who could help me

  13. #28
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You have not answered my question yet, namely, what part do you have trouble understanding?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #29
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    in here T_T

    Code:
    if(isFirst){
            Biggest = V;
            Smallest = V;
            isFirst = FALSE;
        } else {
            Biggest = __max(V , Biggest);
            Smallest = __min(V , Smallest);
        }
    }

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't understand any of the code, or just some specific part such as V or __max or __min?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed