#include <iostream>
using namespace std;


int ScrabbleScore(string word)
{
    int x=0;


    for(int index =0; index < (int)word.length() -1; index ++)
    {
        char ltr = toupper(word[index]);

        if(ltr == 'A' || ltr == 'E' || ltr == 'I' || ltr == 'L' || ltr == 'N' || ltr == 'O' || ltr == 'R' || ltr == 'S' || ltr == 'T' || ltr == 'U')
            x=x+1;
        else if(ltr == 'D' || ltr == 'G')
            x=x+2;
        else if(ltr == 'B' || ltr == 'C' || ltr == 'M' || ltr == 'P')
            x=x+3;
        else if(ltr == 'F' || ltr == 'H' || ltr == 'V' || ltr == 'W' || ltr == 'Y')
            x=x+4;
        else if(ltr == 'K')
            x=x+5;
        else if(ltr == 'J' || ltr == 'X')
            x=x+8;
        else(ltr == 'Q' || ltr == 'Z');
            x=x+10;


    }       



    return x;
}




int main()
{
    string scrab;
    string atsym = "@";

    cout << "This program tests the ScrabbleScore function." << endl;
    cout << "Enter word, ending with " << atsym << "." << endl;

    cout << "Word: ";
    cin >> scrab;

    while(!(scrab == "@"))
    {
        cout << "The basic score for '" << scrab << "' is " << ScrabbleScore(scrab) << endl;

        cout << "Word: ";
        cin >> scrab;       



    }



}

Can anyone tell me when the character 'A' is entered my function returns 0 and not 1?
It will not return anything but 0.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You had a few typos in your code...You really should write a small part of the program compile/debug and then move on.

#include <iostream>
using namespace std;


int ScrabbleScore(string word)
{
	int x = 0;
	int index = 0;

	while (word[index])
	{
		char ltr = toupper(word[index]);
		std::cout << "char->" << ltr << std::endl;

		if(ltr == 'A' || ltr == 'E' || ltr == 'I' || ltr == 'L' || ltr == 'N' || ltr == 'O' || ltr == 'R' || ltr == 'S' || ltr == 'T' || ltr == 'U')
			x += 1;
		else if(ltr == 'D' || ltr == 'G')
			x += 2;
		else if(ltr == 'B' || ltr == 'C' || ltr == 'M' || ltr == 'P')
			x += 3;
		else if(ltr == 'F' || ltr == 'H' || ltr == 'V' || ltr == 'W' || ltr == 'Y')
			x += 4;
		else if(ltr == 'K')
			x += 5;
		else if(ltr == 'J' || ltr == 'X')
			x += 8;
		else if(ltr == 'Q' || ltr == 'Z')//here
			x += 10;
		++index;
	}
	return x;
}




int main()
{
	string scrab;

	cout << "This program tests the ScrabbleScore function." << endl;

	cout << "Word: ";
	cin >> scrab;

	cout << "The basic score for '" << scrab << "' is " << ScrabbleScore(scrab) << endl;

	return 0;
}

Edited 6 Years Ago by gerard4143: n/a

std::cout << "char->" << ltr << std::endl;

What does that line do? I have not been shown that in my class.

std::cout << "char->" << ltr << std::endl;

What does that line do? I have not been shown that in my class.

I was just checking to see what the function was receiving for data...You can delete that line.

Edited 6 Years Ago by gerard4143: n/a

Oh i see thank you very much! One more question if you dont mind, how can i put "@" in a line of code. That is why i have string atsym i thought that might work but it only prints @ also.

Oh i see thank you very much! One more question if you dont mind, how can i put "@" in a line of code. That is why i have string atsym i thought that might work but it only prints @ also.

I'm not really sure what you mean by "put "@" in a line of code". Do you mean take the character '@' and embed it in a string as a sentinel?

Edited 6 Years Ago by gerard4143: n/a

This question has already been answered. Start a new discussion instead.