Score system

Started by
6 comments, last by M0o 12 years, 9 months ago
so here i am again at the end of another chapter and i am stuck yet again. i need to add a scoring system into a "word jumble" game and i know where to start =\




// Word Jumble
// The classic word jumble game where the player can ask for a hint

[size="1"]#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

[size="1"]using namespace std;

[size="1"]int main()
{
enum fields {WORD, HINT, NUM_FIELDS};
const int NUM_WORDS = 5;
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"wall", "Do you feel you're banging your head against something?"},
{"glasses", "These might help you see the answer."},
{"labored", "Going slowly, is it?"},
{"persistent", "Keep at it."},
{"jumble", "It's what the game is all about."}
};

[size="1"] srand(time(0));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS[choice][WORD]; // word to guess
string theHint = WORDS[choice][HINT]; // hint for word

[size="1"] string jumble = theWord; // jumbled version of word
int length = jumble.size();
for (int i=0; i<length; ++i)
{
int index1 = (rand() % length);
int index2 = (rand() % length);
char temp = jumble[index1];
jumble[index1] = jumble[index2];
jumble[index2] = temp;
}

[size="1"] cout << "\t\t\tWelcome to Word Jumble!\n\n";
cout << "Unscramble the letters to make a word.\n";
cout << "Enter 'hint' for a hint.\n";
cout << "Enter 'quit' to quit the game.\n\n";
cout << "The jumble is: " << jumble;

[size="1"] string guess;
cout << "\n\nYour guess: ";
cin >> guess;

[size="1"] while ((guess != theWord) && (guess != "quit"))
{
if (guess == "hint")
cout << theHint;
else
cout << "Sorry, that's not it.";

[size="1"] cout <<"\n\nYour guess: ";
cin >> guess;
}

[size="1"] if (guess == theWord)
cout << "\nThat's it! You guessed it!\n";

[size="1"] cout << "\nThanks for playing.\n";

[size="1"] return 0;
}

Advertisement
i have a basic idea but i dunno what to do with it.

const int score = 0;
enum points {wall = 4, glasses = 7, labored = 7, persistent = 10, hint = -5};
Can't recall if enums are classed as ints or unsigned ints, if unsigned then that -5 for a hint will cause problems. It looks likr your calculating the score based on the length of the word. Since your using std::string you can do:

int totalScore = 0;
int hintPenalty = 5;

int wordScore = theWord.length();
totalScore += wordScore;

or if you use a hint
totalScore -= hintPenalty;

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

thanx, that was so simple sometime i think if i can really do this :( press on i guess thanx again
ok now the hint penalty isnt working =\

Can't recall if enums are classed as ints or unsigned ints, if unsigned then that -5 for a hint will cause problems. It looks likr your calculating the score based on the length of the word. Since your using std::string you can do:

int totalScore = 0;
int hintPenalty = 5;

int wordScore = theWord.length();
totalScore += wordScore;

or if you use a hint
totalScore -= hintPenalty;




hey iv got the points to work but i dunno how to get the hint penalty to work properly can you help please?
if (hintUsed == true) {
totalScore -= hintPenalty;
}

// where hintUsed is a flag set to true when a hint is used

if (hintUsed == true) {
totalScore -= hintPenalty;
}

// where hintUsed is a flag set to true when a hint is used


aaaa thanx i guess i just need to practise using all of these values coz i keep forgetting about them

This topic is closed to new replies.

Advertisement