Scrabble Points Calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Scrabble Points Calculator

Write a program in C that prompts user for a word and the program calculates its scrabble value (1 - AEILNORSTU, 2 - DG, 3 - BCMP, 4 - FHVWY, 5 - K, 8 - JX, 10 - QZ). Any mixture of lowercase and uppercase letters should be allowed.

13th Apr 2018, 6:50 AM
F A
F A - avatar
3 Answers
+ 1
Here simply using switch you can accomplish this. FYI you need tolower() function in ctype.h header file to avoid using switch for both uppercase and lowercase characters https://code.sololearn.com/cNyS0aWF0v85/?ref=app
13th Apr 2018, 8:20 AM
Twenty-three
+ 1
Thanks a lot! Would you mind explaining the while((c=tolower(getchar()))!='\n') bit? I’m a bit new in C and I haven’t learned how to use tolower() and getchar()
13th Apr 2018, 9:31 AM
F A
F A - avatar
+ 1
So when you give input say something like ABCD Then you press ENTER. The enter key is also recorded in the standard input buffer(symbolised by '\n' in C) so getchar() gets a single character from standard input everytime. And when it encounters the '\n' character it is meant to stop the loop or else it will go on forever or return an error as no input exists after you press ENTER key. The tolower() is a function available in "ctype.h" header file. What it does is it takes any alphabetical character and converts them to their lower case equivalent. I used that because "a" and "A" have different ASCII values so are considered different variables and your switch will not identify the new character. So if there is no tolower() you cannot mix uppercase with lowercase.
13th Apr 2018, 10:45 AM
Twenty-three