Advertisement
Guest User

Untitled

a guest
May 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4. #include <ctype.h>
  5.  
  6. /*
  7. In a file called letterlocator.c write a program that
  8. prompts the user for an alphabetic character, and then
  9. prints the position of that letter in the alphabet, starting
  10. with A at position 0. Your program should work for both capital
  11. and lowercase letters, but should reject any input that is not
  12. alphabetical, like '3' or '$'.
  13.  
  14. GetChar
  15. isalpha
  16. */
  17. char alpha;
  18. int alphaPos(int shiftedalpha);
  19.  
  20. int main(void)
  21. {
  22.  
  23. int answer = alphaPos(alpha);
  24. printf("The letter %c equals %i\n\n",alpha,answer);
  25. }
  26.  
  27. int alphaPos(int shiftedalpha)
  28. {
  29. do
  30. {
  31. printf("Enter an alphabet character please:\n");
  32. alpha = GetChar();
  33.  
  34.  
  35. } while (!isalpha(alpha));
  36.  
  37. alpha = toupper(alpha);
  38.  
  39. shiftedalpha = alpha-65;
  40. return shiftedalpha;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement