Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cctype>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int gameScore(string word);
  8. int letterValue(char ch);
  9.  
  10. int main()
  11. {
  12. while(true)
  13. {
  14. char word[80];
  15. cout << "Enter a word: ";
  16. cin.getline(word, 80);
  17.  
  18. if(word[0] == ' ')
  19. break;
  20.  
  21. int score = gameScore(word);
  22. cout << "The score for '" << word << "' is " << score << "n";
  23. }
  24.  
  25. system("PAUSE");
  26. return 0;
  27. }
  28.  
  29. int gameScore(string word)
  30. {
  31. int total = 0;
  32. int length = word.length();
  33.  
  34. for(int i = 0; i < length; i++)
  35. {
  36. total += letterValue(word[i]);
  37. }
  38.  
  39. return total;
  40. }
  41.  
  42. int letterValue(char ch)
  43. {
  44. int value = 0;
  45.  
  46. switch(ch)
  47. {
  48. case 'A': case 'a':
  49. case 'E': case 'e':
  50. case 'I': case 'i':
  51. case 'L': case 'l':
  52. case 'O': case 'o':
  53. case 'R': case 'r':
  54. case 'S': case 's':
  55. case 'T': case 't':
  56. case 'U': case 'u':
  57. value += 1; break;
  58. case 'D': case 'd':
  59. case 'G': case 'g':
  60. value += 2; break;
  61. case 'B': case 'b':
  62. case 'C': case 'c':
  63. case 'M': case 'm':
  64. case 'P': case 'p':
  65. value += 3; break;
  66. case 'F': case 'f':
  67. case 'H': case 'h':
  68. case 'V': case 'v':
  69. case 'W': case 'w':
  70. case 'Y': case 'y':
  71. value += 4; break;
  72. case 'K': case 'k':
  73. value += 5; break;
  74. case 'J': case 'j':
  75. case 'X': case 'x':
  76. value += 8; break;
  77. case 'Q': case 'q':
  78. case 'Z': case 'z':
  79. value += 10; break;
  80. }
  81. return value;
  82. }
  83.  
  84. using namespace std;
  85.  
  86. #include "stdafx.h"
  87.  
  88. system("PAUSE");
  89.  
  90. std::cin.get();
  91.  
  92. return 0;
  93.  
  94. default:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement