why is it always throwing me ERROR? :SCode:int i=0; char a,b,c,pom; do{ scanf ("%c",&pom); if (pom<65 || (pom>90 && pom<97) || pom>122){ printf ("ERROR"); return 0; } if (i==0) a=pom; if (i==1) b=pom; if (i==2) c=pom; i++; } while (i < 3);
why is it always throwing me ERROR? :SCode:int i=0; char a,b,c,pom; do{ scanf ("%c",&pom); if (pom<65 || (pom>90 && pom<97) || pom>122){ printf ("ERROR"); return 0; } if (i==0) a=pom; if (i==1) b=pom; if (i==2) c=pom; i++; } while (i < 3);
Because after every letter you type, you enter a newline character by pressing enter and that causes the ERROR.
Code:while(!asleep) { sheep++; }
how can i fix it? :S while staying at the do while loop, i can do it with if's but i would like to do it with do while...
Add this, to basically ignore newlines
if ( pom == '\n' ) continue;
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Firstly, ditch the magic numbers from your code; you don't want incomprehensible 65's and 122's lying around. Represent them meaningfully. 65 represents a capital A, I think, so replace 65 with 'A' (including the single quotes). This will be translated back into a 65 by the compiler. Likewise, replace the other magic numbers with the characters they represent.
You can add another thing to deal with the newline to your if statement. The newline is represented by '\n'.
Code:while(!asleep) { sheep++; }
solved. i can just input them into one 3-letter word... regarding the "magic" numbers... teachers orders...
another way: space before %c in scanf!
Last edited by turke92; 11-03-2011 at 01:20 PM.
If your teacher is telling you to produce code that's harder to read and less portable, he is the one in need of instruction.
Code:while(!asleep) { sheep++; }
he wants us to learn some ascii values...
Then he should show you THIS rather than starting you off into bad programming practices.
we have tables but we need to know some basic values without checking tables!
look, it's not up to me what he wants us to learn...
New problem!
The printout must be alphabetized but capital letters must be after the small ones if letters are same...
Example:
Input: B b z
Output: b B z
Example 2:
Input: A B z
Output: A B z
I have got to this. Please help me out with solving same letters if one is small and the other one is capital!Code:#include <stdio.h> int main(){ char a,b,c,pom,first,second,third; int i=0; printf ("Input 3 letters: \n"); do{ scanf (" %c",&pom); if (pom<'A' || (pom>'Z' && pom<'a') || pom>'z'){ printf ("Error.");return 0; } if (i==0) a=pom; if (i==1) b=pom; if (i==2) c=pom; i++; } while (i<3); third= (a>b?(a>c?a:c):b>c?b:c); first = (a<b?(a<c?a:c):b<c?b:c); second = (a+b+c) - (najveci+najmanji); printf ("%c %c %c", first, second, third); return 0; }
My bad I forgot to translate "najmanji" and "najveci". "najmanji" is "first" and "najveci" is "third".
P.S. Sorry for double-posting but I can't edit the above post?