-2

I have to make a scrabble scoring game using 2 arrays. The first array holds the user inputted word and the second array holds the value of each letter. Lastly a function is needed to calculate the score. Im having trouble assigning the user values to the second array to get the score and getting the right code for the function.

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <ctime>

using namespace std;

int scoreCalculator(int total);
char userWord;
int points;
int total=0;
int main()
{

char userWord[11];
for (int i=0; i<11; i++)
{
    userWord[i]='\0';
}

cout<<"Enter your word less than 10 letters: "<<endl;
cin>>userWord;
cout<<"Here is the word you inputted: "<<userWord<<endl;  

int scrabblePoints[26]={1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};

for(int j=0; j<26; j++)
{
    userWord[i]
}

cout<<"Here is your score: "<<scoreCalculator(total)<<endl;

}
int scoreCalculator(int total)
{

total+=scrabblePoints[j];

}

This is what I have so far and where im stuck at

javjunkie
  • 3
  • 1
  • 4
  • 1
    And what is the trouble you are having? – NathanOliver Mar 02 '16 at 16:51
  • 1
    Please make sure when you post code that your code is properly indented and readable. – crashmstr Mar 02 '16 at 16:58
  • 3
    Please reconsider your use of bad practices [`using namespace std;`](http://stackoverflow.com/q/1452721/1171191) and [`endl`](http://chris-sharpe.blogspot.co.uk/2016/02/why-you-shouldnt-use-stdendl.html). – BoBTFish Mar 02 '16 at 17:00

1 Answers1

0
#include <iostream>

int main()
{
    std::string input;
    std::cin>>input;

    //  fill this with scrable values
    int scrable_values[26] = {1,3,3,2,1,4,2,4,1,9,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};

    int ans = 0;
    for(int i=0;i<input.size();i++)
    {
        ans += scrable_values[input[i]-97];
    }
    return ans;
}
  • subtracting 97 from the asci values of each character allows you index it in an array. – Dylan plus plus Mar 02 '16 at 17:06
  • Subtracting `'a'` from the *ASCII* values will make the index zero based. Note the use of the character literal which makes programs easier to read. – Thomas Matthews Mar 02 '16 at 17:14
  • I don't know about that though. Its easier for me to subtract numbers, than subtract characters. Plus you save one character by doing it this way.#codeGolf – Dylan plus plus Mar 02 '16 at 17:20