...

View Full Version : Help with adding score to an array



Nerevarine
03-28-2013, 04:27 PM
Hello. I would like some assistance with adding score to my C++ game 'Word Jumble'. Here's the whole code:


// wordJumble.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;


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."}
};

srand(static_cast<unsigned int>(time(0)));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];

string jumble = theWord;
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;
}

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: ";

string guess;
cout << "\n\nYour guess: ";
cin >> guess;

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

cout <<"\n\nYour guess: ";

cin >> guess;
}

int score;

if (guess == theWord)
{
cout << "\nThat's it! You guessed it!\n";
}

cout << "\nThanks for playing.\n";
cout << "Your score is " << score << "!";


return 0;
}



I am trying to get it so that when a word is correctly guessed, it adds 10 to the 'score' variable. I tried some incrementing, but was unable to get it to work. Can anyone help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum