|
-
Feb 11th, 2001, 08:43 AM
#1
Thread Starter
New Member
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);
}
-
Feb 11th, 2001, 09:48 AM
#2
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|