Can anyone please help?
I am sure you were all beginners once.
I tried following all the suggestions.
This code just won't work....
Please indicate where I am making mistake...:0(
I am just a girl trying to learn C...
Can anyone please help?
I am sure you were all beginners once.
I tried following all the suggestions.
This code just won't work....
Please indicate where I am making mistake...:0(
I am just a girl trying to learn C...
Print the number as a character if that's what you're trying to do, as you did in your first printf but not the second.
[edit] Why did you choose to limit the number from 4 to 100, by the way? If you're trying to limit the program to printing only printable characters, use the return value of isprint() in <ctype.h>:Code:#include <stdio.h> main(void){ int Number; do{ printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf("%d",& Number); if(Number < 4 || Number > 100) printf("\nIncorrect! Number has to be between 4 and 100. TRY again!\n\n"); } while(Number < 4 || Number > 100); printf("%c\n", Number); /* if ( Number < 4 || Number > 100 ) Don't have to check ) */ printf("Thank you for entering the number %c!\n", Number); }
[/edit]Code:#include <ctype.h> /* ... */ if(!isprint(Number)) printf(/* ... */);
Last edited by dwks; 10-21-2006 at 02:59 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I changed the %c, but when I try to execute it all it does is this:
Type an ASCII code 4 through 100 to get their
correspondent character constants: 6
and then ends....
Thank you for help!
Code:#include <stdio.h> main(void){ int Number; do{ printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf("%d",& Number); if(Number < 4 || Number > 100) printf("\nIncorrect! Number has to be between 4 and 100. TRY again!\n\n"); } while(Number < 4 || Number > 100); printf("%c\n", Number); /* if ( Number < 4 || Number > 100 ) Don't have to check ) */ printf("Thank you for entering the number %c!\n", Number); }
No it doesn't! Your code works fine!Oh, and no one cares what gender you are. They only care if you're paying attention. You aren't. You fail.Code:Type an ASCII code 4 through 100 to get their correspondent character constants: 99 Thank you for entering the number c!
Quzah.
Hope is the first step on the road to disappointment.
It may end if the windows console dissapears before you can see what it says, but I suspect you would have had that problem with previous programs if that was the case.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Well, it wasn't working...I am paying attention...Maybe dwks is right and the window console dissapears before I can see what is says.I will try it on my friend's computer.
I have two more questions:
How could I use this loop to repeatedly ask the user to enter a valid decimal number in case input is not between 4 and 100?
How can I make the program end when the user enters number 3?
Thanks a lot! )
Yes it was. No you're not. Read the FAQ. Use a loop. Post your code.
Quzah.
Hope is the first step on the road to disappointment.
This is my code.
I have two more questions:
How could I use a loop to repeatedly ask the user to enter a valid decimal number in case input is not between 4 and 100?
How can I make the program end when the user enters number 3?
Thanks a lot!
Code:#include <stdio.h> main(void){ int Number; do{ printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf("%d",& Number); if(Number < 4 || Number > 100) printf("\nIncorrect! Number has to be between 4 and 100. TRY again!\n\n"); } while(Number < 4 || Number > 100); printf("%c\n", Number); /* if ( Number < 4 || Number > 100 ) Don't have to check ) */ printf("Thank you for entering the number %c!\n", Number); }
Seems like you're doing that to me with your do-while loop.How could I use a loop to repeatedly ask the user to enter a valid decimal number in case input is not between 4 and 100?
Hello return 0;. Look at this for a few pointers. Oh, and BTW, main returns an int.How can I make the program end when the user enters number 3?
Also, you may want to check out this and this to see if that resolves any of your console problems.
Notice, as well, that most of this stuff could be found on the site already. You didn't really need to make a whole thread.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
No, she's not. What everyone has been telling you is to "use a loop". What they are trying to tell you is that you'll need a while() / do...while() loop around all your current code. You'll want the start of it before your do, then you'll want the end of it after the print statement. Also, you'll need to control the print statement with an if().Originally Posted by Happy_Reaper