I'm trying to simulate the spin of a slot machines [reel1][reel2][reel3] so they look like they are in motion.

i'm getting this error:
Error 2 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

//rotation of the reels


using namespace std;

int main()
{
//variables
	string reelArray[7];
	int reel1;
	int reel2;
	int reel3;
	int spin = 0;

	reelArray[0] = "[  LEMON   ]";
	reelArray[1] = "[  ORANGE  ]";
	reelArray[2] = "[  HEART   ]";
	reelArray[3] = "[  SMILEY  ]";
	reelArray[4] = "[  STAR    ]";
	reelArray[5] = "[  MOON    ]";
	reelArray[6] = "[  SEVEN   ]";
	
	

	srand(time(NULL));//seed RNG

	for(int i = 0; i < 7; i++)
	{
		int max = 7;//initialize max

		reel1 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7
		reel2 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7
		reel3 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7
		
		

		if(reelArray[i] == (reel1 - 1))
		{
			spin++;
			cout<<reelArray[i]<<' '<<reelArray[i]<<' '<<reelArray[i]endl;
			cout<<reel1<<endl;//testing output
			cout<<reel2<<endl;//testing output
			cout<<reel3<<endl;//testing output
			switch(spin)
			{
			case 0:
				Sleep(100);
				break;
			case 1:
				Sleep(120);
				break;
			case 2:
				Sleep(175);
				break;
			case 3:
				Sleep(250);
				break;
			case 4:
				Sleep(350);
				break;
			case 5:
				Sleep(450);
			default:
				Sleep(1000);
			}
		
		}
	}
return 0;
}

this program is a stub im working on to eventually add to my full program.

please let me know if im going with this is the wrong direction!

do you have #include <string> ?

This is a problem

if(reelArray[i] == (reel1 - 1))

You're comparing a string to an int - not gonna work, not making any sense.

Do you mean to be comparing reelArray to reelArray[reel1] ?

do you have #include <string> ?

yes

i have:

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

do you have #include <string> ?

This is a problem

if(reelArray[i] == (reel1 - 1))

You're comparing a string to an int - not gonna work, not making any sense.

Do you mean to be comparing reelArray to reelArray[reel1] ?

let me see.....

now it works but reel1 is the same as reel2 and reel3
even when they are not suposed to be

//rotation of the reels
//----------------------
#include<iostream>
#include<string>
#include<iomanip>
#include<ctime>
#include<windows.h>

using namespace std;

int main()
{
//variables
	string reelArray[7];
	int reel1;
	int reel2;
	int reel3;
	int spin = 0;

	reelArray[0] = "[  LEMON   ]";
	reelArray[1] = "[  ORANGE  ]";
	reelArray[2] = "[  HEART   ]";
	reelArray[3] = "[  SMILEY  ]";
	reelArray[4] = "[  STAR    ]";
	reelArray[5] = "[  MOON    ]";
	reelArray[6] = "[  SEVEN   ]";
	
	

	srand(time(NULL));//seed RNG

	for(int i = 0; i < 7; i++)
	{
		int max = 7;//initialize

		reel1 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7
		reel2 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7
		reel3 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7
		
		

		if(reelArray[i] == reelArray[reel1 - 1] || reelArray[i] == reelArray[reel2 - 1] || reelArray[i] == reelArray[reel3 - 1])
		{
			spin++;
			cout<<reelArray[i]<<' '<<reelArray[i]<<' '<<reelArray[i]<<endl;
			cout<<reel1<<endl;
			cout<<reel2<<endl;
			cout<<reel3<<endl;
			switch(spin)
			{
			case 0:
				Sleep(100);
				break;
			case 1:
				Sleep(120);
				break;
			case 2:
				Sleep(175);
				break;
			case 3:
				Sleep(250);
				break;
			case 4:
				Sleep(350);
				break;
			case 5:
				Sleep(450);
			default:
				Sleep(1000);
			}
		
		}
	}
return 0;
}
cout<<reelArray[i]<<' '<<reelArray[i]<<' '<<reelArray[i]<<endl;

You're telling it to display the same thing three times!

reel1 = 1 + rand()%(max - 1 + 1);//RNG 1 through 7

Why the adding and subtracting 1 to max? Net effect is 0 change.
Then you have to subtract 1 when using reel1 as index, so why add one at all, use range 0-6.

Perhaps it would help if you explained just what your logic is for spinning the wheels. Writing it out might help you to understand what you're trying to do, and help me and anyone else to better help you.

commented: thx your pretty helpful, i got exactly what you meant +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.