Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cctype>
- #include <string>
- using namespace std;
- int gameScore(string word);
- int letterValue(char ch);
- int main()
- {
- while(true)
- {
- char word[80];
- cout << "Enter a word: ";
- cin.getline(word, 80);
- if(word[0] == ' ')
- break;
- int score = gameScore(word);
- cout << "The score for '" << word << "' is " << score << "n";
- }
- system("PAUSE");
- return 0;
- }
- int gameScore(string word)
- {
- int total = 0;
- int length = word.length();
- for(int i = 0; i < length; i++)
- {
- total += letterValue(word[i]);
- }
- return total;
- }
- int letterValue(char ch)
- {
- int value = 0;
- switch(ch)
- {
- case 'A': case 'a':
- case 'E': case 'e':
- case 'I': case 'i':
- case 'L': case 'l':
- case 'O': case 'o':
- case 'R': case 'r':
- case 'S': case 's':
- case 'T': case 't':
- case 'U': case 'u':
- value += 1; break;
- case 'D': case 'd':
- case 'G': case 'g':
- value += 2; break;
- case 'B': case 'b':
- case 'C': case 'c':
- case 'M': case 'm':
- case 'P': case 'p':
- value += 3; break;
- case 'F': case 'f':
- case 'H': case 'h':
- case 'V': case 'v':
- case 'W': case 'w':
- case 'Y': case 'y':
- value += 4; break;
- case 'K': case 'k':
- value += 5; break;
- case 'J': case 'j':
- case 'X': case 'x':
- value += 8; break;
- case 'Q': case 'q':
- case 'Z': case 'z':
- value += 10; break;
- }
- return value;
- }
- using namespace std;
- #include "stdafx.h"
- system("PAUSE");
- std::cin.get();
- return 0;
- default:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement