i am having a few errors compiling a code in visual C++ with my jumble word code, can anyone help?

//word jumble

#include <iostream>
#include <string.h>
#include <cstdlib>
#include <ctime>

using namspace 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 agianst 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(time(0));
	int choice = (rand()% NUM_WORDS);
	string theWord = WORDS[choice][WORD];	//word to guess
	string theHint = WORDS[choice][HINT];	//hint for word
	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[index2];
		jumble[index1] = jumble[index2];
		jumble[index2] = temp;
	}

	cout<<"Welcome to Word Jumble"<<endl;
	cout<<"Unscramble the letters to make a word."<<endl;
	cout<<"enter 'hint' for a hint."<<endl;
	cout<<"enter 'quit' to quit the game."<<endl;
	cout<<"the jumble is: "<<jumble;

	string guess;
	cout<<"your guess: ";
	cin>>guess;

	while((guess != theWord) &&(guess != 'quit'))
	{
		if (guess == 'hint')
		{
			cout<<theHint;
		}
		else 
		{
			cout<<"sorry that is not it"<<endl;
		}

		cout<<"\n\nYour Guess: "<<endl;
		cin>>guess;
	}

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

	cout<<"\nthanks for playing\n";

	return 0;
}

i am having a few errors compiling a code in visual C++ with my jumble word code, can anyone help?

Yes we can, if you give us an idea what's wrong. We can't see your screen with the errors.

Check your "namspace" line. Also include <string> for std::string, not <string.h> (string.h has strcpy, strcmp etc stuff for C-strings). That's what I get at a glance, there may be more.

And yes, you should post your error messages as we should not be your compiling service.

Check your "namspace" line. Also include <string> for std::string, not <string.h> (string.h has strcpy, strcmp etc stuff for C-strings). That's what I get at a glance, there may be more.

And yes, you should post your error messages as we should not be your compiling service.

i should have posted there error messages, but there were 50 somthing...i did not see the two typo's of namespace and <string>. ty

ok, without the small typing error, this is my new code

//word jumble

#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 agianst 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(time(0));
	int choice = (rand()% NUM_WORDS);
	string theWord = WORDS[choice][WORD];	//word to guess
	string theHint = WORDS[choice][HINT];	//hint for word
	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[index2];
		jumble[index1] = jumble[index2];
		jumble[index2] = temp;
	}

	cout<<"Welcome to Word Jumble"<<endl;
	cout<<"Unscramble the letters to make a word."<<endl;
	cout<<"enter 'hint' for a hint."<<endl;
	cout<<"enter 'quit' to quit the game."<<endl;
	cout<<"the jumble is: "<<jumble;

	string guess;
	cout<<"your guess: ";
	cin>>guess;

	while((guess != theWord) &&(guess != 'quit'))
	{
		if (guess == 'hint')
		{
			cout<<theHint;
		}
		else 
		{
			cout<<"sorry that is not it"<<endl;
		}

		cout<<"\n\nYour Guess: "<<endl;
		cin>>guess;
	}

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

	cout<<"\nthanks for playing\n";

	return 0;
}

and here are all 25 errors

1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(23) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'int'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(120) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(110) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(100) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\streambuf(557) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\streambuf(557) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\streambuf(557) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\streambuf(557) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(180) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(180) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(180) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(180) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2254) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2254) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2254) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2254) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2061) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2061) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2061) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2061) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(91) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(91) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(91) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(91) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2676: binary '!=' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : fatal error C1903: unable to recover from previous error(s); stopping compilation

i can not make heads or tails about these errors, they all have to do with my while loop and the srand(time(0));

Edited 6 Years Ago by totalwar235: forgot a word (the without)

i should have posted there error messages, but there were 50 somthing...i did not see the two typo's of namespace and <string>. ty

So just post the first 5 or so. Usually the first one you fix gets rid of a lot of the errors.

You represent strings just fine elsewhere in the same program, what happened with these two?

while((guess != theWord) &&(guess != 'quit'))
{
     if (guess == 'hint')

can anyone please help me, this is a bump

Comments
You don't BUMP on this site. You answer the question(s) asked.

Post your latest code please. Did you make the changes in my last post with regards to double quotes where you had single quotes?

the code is still

//word jumble

#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 agianst 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(time(0));
	int choice = (rand()% NUM_WORDS);
	string theWord = WORDS[choice][WORD];	//word to guess
	string theHint = WORDS[choice][HINT];	//hint for word
	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[index2];
		jumble[index1] = jumble[index2];
		jumble[index2] = temp;
	}

	cout<<"Welcome to Word Jumble"<<endl;
	cout<<"Unscramble the letters to make a word."<<endl;
	cout<<"enter 'hint' for a hint."<<endl;
	cout<<"enter 'quit' to quit the game."<<endl;
	cout<<"the jumble is: "<<jumble;

	string guess;
	cout<<"your guess: ";
	cin>>guess;

	while((guess != theWord)&&(guess != 'quit'))
	{
		if (guess == 'hint')
		{
			cout<<theHint;
		}
		else 
		{
			cout<<"sorry that is not it"<<endl;
		}

		cout<<"\n\nYour Guess: "<<endl;
		cin>>guess;
	}

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

	cout<<"\nthanks for playing\n";

	return 0;
}

the first five error codes are

>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(23) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'int'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(120) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(110) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(100) : see declaration of 'std::operator !='
1>c:\users\reed\documents\visual studio 2008\projects\learning\learning\wordjumble.cpp(48) : error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\streambuf(557) : see declaration of 'std::operator !='

If you continue to ignore people, you'll get more -rep.

Read jonsca's posts again. A big part of your answer is right there staring you in the face. Check your use of single vs. double quotes.

Edit:
nvm... I missed posts 11, 12 while catching up.

Edited 6 Years Ago by Fbody: n/a

Then why are you bumping the thread when Jonsca pointed out a problem? Fix the problem and try it again.

In case you didn't understand his post, check you book for the difference between ' and "


[edit]Wow, a plethora of replies during compose time!![/edit]

Edited 6 Years Ago by WaltP: n/a

disregarding all above posts.

the program works but has some minor errors. when i play the game the letters when scrambled change(not all but some), like a "J" to a "L". what would be the easiest way to fix this?

disregarding all above posts.

the program works but has some minor errors. when i play the game the letters when scrambled change(not all but some), like a "J" to a "L". what would be the easiest way to fix this?

What does the algorithm for scrambling look like, how does it work?

A char's value is actually and integer whose value represents a specific character. (Google "ASCII Table" for more information.) You're most likely changing the numeric values of the chars that make up the strings instead of re-arranging them.

srand(time(0));
	int choice = (rand()% NUM_WORDS);
	string theWord = WORDS[choice][WORD];	//word to guess
	string theHint = WORDS[choice][HINT];	//hint for word
	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[index2];
		jumble[index1] = jumble[index2];
		jumble[index2] = temp;
	}

this is the algorithm

i was thinking that i could just do if statements for each letter and check it against all the other ones to make sure it had the correct ones.

This article has been dead for over six months. Start a new discussion instead.