I think it would be best to stick with what Dweia said.
I think it would be best to stick with what Dweia said.
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
Thank you guys!
Hi, I am trying to get this to work, but it won't compile. Please understand I am just the beginner.
Thanks in advance for any help!
Code:#include <stdio.h> main(){ float fNumber; int input; printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf ("%d",& input); printf("%8c\n", input); while ( fNumber=>4;fnumber <=100) { printf("Icorrect! Number has to be between 4 and 100. TRY again\n"); scanf("%g",&fNumber); } /* if ( fNumber=>4;fnumber <=100 ) Don't have to check ) */ printf("Thank you for entering the number %g!\n", fNumber); }
main() should be int main(void)
while is in the format while (true statement), which cannot have ; in the ().
EDIT: You are also using an uninitialized variable fNumber.
Still getting this error:
In function âmainâ:
13: error: expected expression before â>â token
Thank you for help!
Last edited by Newbie999; 10-20-2006 at 08:26 PM.
Ah, didn't see that one. . . the comparitive opp is >=, not =>.
Still gettiing the same error...
In function âmainâ:
13: error: expected â)â before â;â token
Code:#include <stdio.h> main(void){ float Number; int input; printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf ("%d",& input); printf("%8c\n", input); while ( Number >=4; Number =<100) { printf("Icorrect! Number has to be between 4 and 100. TRY again\n"); scanf("%g",&Number); } /* if ( Number>=4;number =<100 ) Don't have to check ) */ printf("Thank you for entering the number %g!\n", Number); }
Last edited by Newbie999; 10-20-2006 at 08:26 PM.
There is no operator =<, and what is the semicolon supposed to do for you?Code:while ( Number >=4; Number =<100) {
What do input and Number have to do with one another? And do you know that %g is used with floating point values?
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
See #19
EDIT: Beaten. Bummer.
Thanks Dave_Sinkula and Kennedy!
As you can see, I am just the beginner, trying to learn on my own....
I made some changes in the code, but still won't compile. I am just very confused.
I appreciate your help!
Code:#include <stdio.h> main(void){ float Number; printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf ("%g",& input); printf("%8c\n", input); while ( Number >=4,100>=Number) { printf("Icorrect! Number has to be between 4 and 100. TRY again\n"); scanf("%g",&Number); } /* if ( Number >=4,100>=Number ) Don't have to check ) */ printf("Thank you for entering the number %g!\n", Number); }
O.K now it compiled, but it won't convert the ASCII codes...
Can anyone help please?
Thanks!
Code:#include <stdio.h> main(void){ float Number; printf("Type an ASCII code 4 through 100 to get their\n"); printf("correspondent character constants: "); scanf("%g",& Number); printf("%8c\n", Number); while ( Number >=4) while ( 100>=Number){ printf("Icorrect! Number has to be between 4 and 100. TRY again\n"); scanf("%g",&Number); } /* if ( Number >=4)(100>=Number ) Don't have to check ) */ printf("Thank you for entering the number %g!\n", Number); }
Hey, hey... You cannot use two expression within the while loop's brackets. Remember the syntax for while loop:
So, you can only write either 'Number >= 4' or 'Number >= 100' in the brackets. Ow yeah, you the variable's name should come out first before the value--> 'Number >=100', not '100>=Number'....Code:while(expression) { statements; }
If I can use ony one expression, How can I then convert the decimal ASCII codes 4 through 100 to their correspondent character constant?
Thanks for your help!
Hello,
You should use integer data type for number. Otherwise, it wouldn't be able to be converted to character using %c. So, use int Number and replace all %g with %d for integer. OK?
Hmm, actually what do u expect by writing :
Let's see... if u want to ask the user again after he has entered wrong number, you can use a do-while loop which covers the whole thing from entering number to the end. And then, put a condition/expression that will keep on asking the user if the entered number is not between 4 and 100, such as:Code:printf("Icorrect! Number has to be between 4 and 100. TRY again\n"); scanf("%g",&Number);
Note that: || is a an OR operator.Code:do { statements; } while( Number < 4 || Number > 100);
TRY AGAIN! Do not give up!
Why are you using a float? Read an integer. Or better yet, just use a char.
Why are you checking for >= 100, since 100 is allowed. You just told them 100 is ok. Now your ugly loop prevents 100.
Why are you using %g to print? That won't print a character. Use %c for chatacters. Go read the format specifiers.
[edit]
Curses, foiled again!
[/edit]
Quzah.
Hope is the first step on the road to disappointment.