Results 1 to 2 of 2

Thread: Help a old man who is going insane

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Mirfield,West Yorkshire,Englan
    Posts
    11

    Angry

    I am new to C and I am doing a course in VB but I have to understand C first I know you will not do my homework for me but can someone please give me a clue

    This is a question I am on with I have input two characters and show the characters from lowest to highest and highest to lowest

    this is my code at pres

    /*characters.c*/

    #include <stdio.h>

    void main ()

    {

    char ch1,ch2,loop,lowest highest,

    printf("Enter two characters >");
    scanf("%c%c",&lowest,&highest);

    ch1 = 0;
    ch2 = 127;

    if (ch1 <= ch2)
    for(loop = lowest;loop <=highest;loop++)
    printf("%c",loop);
    if (ch1 >= ch2)
    for(loop = highest;loop >= lowest;loop++);
    printf("%c",loop);
    }

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I don't really see the need for ch1 and ch2, what are they there for?

    Also, your two expressions (ch1 <= ch2) and (ch1 >= ch2) can both return true if ch1==ch2. You need to change it slightly so they don't overlap.

    You may also want to convert the two characters to the same case (upper or lower case, you choose) when you're doing the comparison, otherwise you may get the wrong alphabetical order if the characters are different case.
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width