1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
void intro();
bool keepPlaying();
int giveValue( string givenWord);
//void displayValue(int totalValue);
bool checkLettersRow(string givenWord);
int main()
{
string givenWord;
int totalValue=0;
intro();
do
{
cout << "Enter a word to see its value:";
cin >> givenWord;
/*for (int i=0; i<givenWord.size(); i++)
{
cout << "Letter at position" << i << " is [" << givenWord[i] << "]" << endl;
}*/
totalValue = giveValue(givenWord);
cout <<"totalvalue:" << totalValue <<" givenWord:"<< givenWord << endl;
}
while(keepPlaying());
return 0;
}
void intro()
{
cout << "Words With Ken" << endl;
cout << "Each letter has the following values:" << endl;
cout << "A, B, C, D, E, F, G are worth 1 point" << endl;
cout << "H, I, J, K, L, M , N are worth 2 points" << endl; ///little == 13points before doubling 26 after
cout << "O, P, Q, R, S, T, U are worth 3 points" << endl;
cout << "V, W, X, Y, Z are worth 5 points." << endl;
}
bool keepPlaying()
{
char ch;
cout << "Would you like to enter another word? [Y/N]";
cin >> ch;
if ( ch == 'Y' || ch == 'y') return true;
return false;
}
int giveValue(string givenWord)
{
int j=0, wordValue=0;
for (j=0; givenWord[j]<givenWord.size(); j++)
{
if (givenWord[j]=='a'||givenWord[j]=='A'|| givenWord[j] == 'B'||givenWord[j] =='b'||givenWord[j] =='C'|| givenWord[j]=='c'||
givenWord[j]=='D'||givenWord[j]=='d'||givenWord[j]=='E'||givenWord[j]=='e'||givenWord[j]=='F'||givenWord[j]=='f'||
givenWord[j]=='G'||givenWord[j]=='g')
wordValue+=1;
else if (givenWord[j]=='H'||j=='h'||givenWord[j]=='I'||givenWord[j]=='i'||givenWord[j]=='J'||givenWord[j]=='j'||
givenWord[j]=='K'||givenWord[j]=='k'||givenWord[j]=='L'||givenWord[j]=='l'||givenWord[j]=='M'||givenWord[j]=='m'||
givenWord[j]=='N'||givenWord[j]=='n')
wordValue+=2;
else if(givenWord[j]=='O'||givenWord[j]=='o'||givenWord[j]=='P'||givenWord[j]=='p'||givenWord[j]=='Q'||givenWord[j]=='q'||
givenWord[j]=='R'||givenWord[j]=='r'||givenWord[j]=='S'||givenWord[j]=='s'||givenWord[j]=='T'||givenWord[j]=='t'||
givenWord[j]=='U'||givenWord[j]=='u')
wordValue+=3;
else if(givenWord[j]=='V'||givenWord[j]=='v'||givenWord[j]=='W'||givenWord[j]=='w'||givenWord[j]=='X'||givenWord[j]=='x'||
givenWord[j]=='Y'||givenWord[j]=='y'||givenWord[j]=='Z'||givenWord[j]=='z')
wordValue+=5;
}
/* checkLettersRow(j,givenWord);
{
if (checkLettersRow == true)
return wordValue*=2;
}*/
return wordValue;
}
bool checkLettersRow(string givenWord)
{
for (int i=0; i<givenWord.size(); i++)
{
if (givenWord[i]==givenWord[i+1])
{
return true;
}
return false;
}
}
/*void displayValue(int totalValue)
{
cout << givenWord << givenWord [i] << " = " totalValue;
}*/
|