So i recently started c language with no prior knowledge of coding or computer science. Wrote this piece of code to find value of a word using scrabble points as below: 1:AEILNORSTU 2:DG 3:BCMP 4:FHVWY 5:K 8:JX 10:QZ.
# include <stdio.h>
# include <ctype.h>
# include <conio.h>
int main (void)
{
int n=0;
char ch;
clrscr();
printf("Enter the SCRABBLE word\n");
ch = getchar();
while(ch!='\n')
{
toupper(ch);
if(ch =='A'||'E'||'I'||'L'||'N'||'O'||'R'||'S'||'T'||'U')
n=n+1;
else if (ch =='D'||'G')
n=n+2;
else if (ch =='B'||'C'||'M'||'P')
n=n+3;
else if (ch =='F'||'H'||'V'||'W'||'Y')
n=n+4;
else if (ch =='K')
n=n+5;
else if (ch =='J'||'X')
n=n+8;
else if (ch =='Q'||'Z')
n=n+10;
ch = getchar();
}
printf("The value is %d",n);
return 0;
}
So what happens when i run this code is that : Enter the SCRABBLE word eg: barrier The value is 7 though it should be 9 as b carries 3 points as noted above the code,a carries 1,r carriers 1,again r 1 point,i carries 1 point and the last two alphabet are one point each so thats 3+1+1+1+1+1+1=9