2 Replies - 411 Views - Last Post: 07 October 2013 - 12:38 AM Rate Topic: -----

#1 blakeyanks2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-October 13

intro to programming

Posted 06 October 2013 - 11:14 PM

I have to write a program that prompts the user for a lower case letter between b and y and prints that letter and the two next to in upper case. For example:
Lower case letter between b and y: d
D follows C and precedes E.

I am confused on how to get it to print the uppercase letter
Is This A Good Question/Topic? 0
  • +

Replies To: intro to programming

#2 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: intro to programming

Posted 07 October 2013 - 12:33 AM

There are a few ways to do this. Easiest one in C, is to include the ctype.h header file, then use the toupper() function to change the letter to uppercase.

You could also calculate it out manually:

int offset = 'a'- 'A'; //char offset also works

your char - offset will equal your char in uppercase.

The above works with PC's, but will not work with big computers if they use a character set other than ASCII.

If you haven't downloaded an ASCII table from the net, you should do so. They're free, and programmers need one, for reference. I keep an image of one, right on my desktop. A couple clicks with the mouse, and I'm right there.
Was This Post Helpful? 0
  • +
  • -

#3 Mrk  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 66
  • Joined: 03-December 09

Re: intro to programming

Posted 07 October 2013 - 12:38 AM

I assume you know how to print out the answer in lower case right. For example, user inputs m so the programs prints out l and n. Then all you have to do is convert to uppercase. There are at least three ways to do that and the most basic way is to just subtract 32 from the lower case to get the upper case. For example, l has an ASCII value of 108, so subtract 32 to get uppercase L, which has an ASCII value of 76.

Look at an ASCII chart and see what the relationship is between the values for the lowercase set of letters and the uppercase set of letters. You will see that the lowercase letters are always 32 higher than the uppercase letters.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1