By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 2,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

ASCII Code???

P: n/a
i couldnt figure out how i am supposed to find the ASCII code is there
any way to do it? and main problem is i am not sure so i wanted to ask
is it going to display 'a' ? am i right?
What is the ASCII code displayed by the cout at Line 19?
12 char f1(char a) {
13 if (a < 'a') return a;
14 else f1(a - 1);
15 } // end f1
16 int main (int argc, char **argv)
17 {
18 char reply;
19 cout << (int)f1('a') << endl;

please help me out!!!!!

Mar 23 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
ia*************@gmail.com wrote:
i couldnt figure out how i am supposed to find the ASCII code is there
any way to do it? and main problem is i am not sure so i wanted to ask
is it going to display 'a' ? am i right?
What is the ASCII code displayed by the cout at Line 19?
12 char f1(char a) {
13 if (a < 'a') return a;
14 else f1(a - 1);
15 } // end f1
16 int main (int argc, char **argv)
17 {
18 char reply;
19 cout << (int)f1('a') << endl;

please help me out!!!!!
Did you try it?

--
Ian Collins.
Mar 23 '07 #2

P: n/a
did i try what i have this much of the code i cannot compile it so i
am trying to understand by reading the code and my understanding it
should be'a' displayed. What i am asking is am i right or not?

Mar 23 '07 #3

P: n/a
ia*************@gmail.com wrote:
did i try what i have this much of the code i cannot compile it so i
am trying to understand by reading the code and my understanding it
should be'a' displayed. What i am asking is am i right or not?
Please keep the context you are replying to.

Why couldn't you compile it, perhaps if we help you with that, you can
run your own tests.

By the way, it can't output 'a' because you have cast the result to int.

--
Ian Collins.
Mar 23 '07 #4

P: n/a
On Mar 22, 6:41 pm, Ian Collins <ian-n...@hotmail.comwrote:
ianenis.tiry...@gmail.com wrote:
did i try what i have this much of the code i cannot compile it so i
am trying to understand by reading the code and my understanding it
should be'a' displayed. What i am asking is am i right or not?

Please keep the context you are replying to.

Why couldn't you compile it, perhaps if we help you with that, you can
run your own tests.

By the way, it can't output 'a' because you have cast the result to int.

--
Ian Collins.
no what i mean if it is 'a' it should pump out the ASCII code for the
variable right? but so that what you are saying it cannot be a's ASCII
code right?

the thing is this code is not to compile it is and extra credit for me
and this is really what i am supposed to do. if you look at it it
wouldnt even work if you run the program i guess. -at lest not with
the info given -

Mar 23 '07 #5

P: n/a
ia*************@gmail.com wrote:
On Mar 22, 6:41 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>ianenis.tiry...@gmail.com wrote:
>>>did i try what i have this much of the code i cannot compile it so i
am trying to understand by reading the code and my understanding it
should be'a' displayed. What i am asking is am i right or not?

Please keep the context you are replying to.

Why couldn't you compile it, perhaps if we help you with that, you can
run your own tests.

By the way, it can't output 'a' because you have cast the result to int.
*Please* don't quote signatures.
>
no what i mean if it is 'a' it should pump out the ASCII code for the
variable right? but so that what you are saying it cannot be a's ASCII
code right?
Ah, I see now. Sorry I though you where looking for 'a' as the output,
not its ASCII value.

As written the code will not output the ASCII value for 'a'. I think
calling f1's parameter a is causing confusion. Look at the else branch,
what is being returned from it? What happens when the input is 'a'?

Another thing, don't use <iostream.h>, the correct header is <iostream>.
the thing is this code is not to compile it is and extra credit for me
and this is really what i am supposed to do. if you look at it it
wouldnt even work if you run the program i guess. -at lest not with
the info given -
No, it won't.

--
Ian Collins.
Mar 23 '07 #6

P: n/a
On Mar 22, 7:04 pm, Ian Collins <ian-n...@hotmail.comwrote:
ianenis.tiry...@gmail.com wrote:
On Mar 22, 6:41 pm, Ian Collins <ian-n...@hotmail.comwrote:
>ianenis.tiry...@gmail.com wrote:
>>did i try what i have this much of the code i cannot compile it so i
am trying to understand by reading the code and my understanding it
should be'a' displayed. What i am asking is am i right or not?
>Please keep the context you are replying to.
>Why couldn't you compile it, perhaps if we help you with that, you can
run your own tests.
>By the way, it can't output 'a' because you have cast the result to int.

*Please* don't quote signatures.
no what i mean if it is 'a' it should pump out the ASCII code for the
variable right? but so that what you are saying it cannot be a's ASCII
code right?

Ah, I see now. Sorry I though you where looking for 'a' as the output,
not its ASCII value.

As written the code will not output the ASCII value for 'a'. I think
calling f1's parameter a is causing confusion. Look at the else branch,
what is being returned from it? What happens when the input is 'a'?

Another thing, don't use <iostream.h>, the correct header is <iostream>.
the thing is this code is not to compile it is and extra credit for me
and this is really what i am supposed to do. if you look at it it
wouldnt even work if you run the program i guess. -at lest not with
the info given -

No, it won't.

--
Ian Collins.- Hide quoted text -

- Show quoted text -
ok thats the thing because when input is 'a' then it returns 'a' but
else it returns 'a-1' so there should be two different outputs
right? but the question asks ASCII code displayed by the line 19 so i
am really confused?

Mar 23 '07 #7

P: n/a
ia*************@gmail.com wrote:
>>
>>>the thing is this code is not to compile it is and extra credit for me
and this is really what i am supposed to do. if you look at it it
wouldnt even work if you run the program i guess. -at lest not with
the info given -

No, it won't.
*Please* don't quote signatures - that's the bit after the "-- ".
>
ok thats the thing because when input is 'a' then it returns 'a' but
else it returns 'a-1' so there should be two different outputs
right? but the question asks ASCII code displayed by the line 19 so i
am really confused?
Putting back your original code:

12 char f1(char a) {
13 if (a < 'a') return a;

This returns a when a is less than 'a'.

14 else f1(a - 1);

This doesn't return anything.

15 } // end f1
16 int main (int argc, char **argv)
17 {
18 char reply;
19 cout << (int)f1('a') << endl;

The output is undefined.

--
Ian Collins.
Mar 23 '07 #8

P: n/a

<ia*************@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
>i couldnt figure out how i am supposed to find the ASCII code is there
any way to do it? and main problem is i am not sure so i wanted to ask
is it going to display 'a' ? am i right?
What is the ASCII code displayed by the cout at Line 19?
12 char f1(char a) {
13 if (a < 'a') return a;
14 else f1(a - 1);
malformed code. Not all control paths of f1 return a value.

Was this supposed to be
else
return f1(a-1);
???
15 } // end f1
16 int main (int argc, char **argv)
17 {
18 char reply;
19 cout << (int)f1('a') << endl;

please help me out!!!!!

Mar 23 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.