PDA

Click to See Complete Forum and Search --> : Help a old man who is going insane


Robert Briggs
Feb 11th, 2001, 07:43 AM
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);
}

HarryW
Feb 11th, 2001, 08:48 AM
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.