hi everyone, im having problems with my loop in my assignment im working on.
im not tryin to get the code from you guys. but would like some pointers on what im doing wrong.
im tryin to figure out why my "else" code wont work?
i've tried to look for anything that can help me out with it, but how i set it up, looks like all the others i've seen.
here is my code so far. can anyone tell me what im doing wrong with my "else" part?

#include <iostream>

using namespace std;

int main( )
{
	srand(time(0)); 
	
	int wheelNumber = rand() % 36 + 1; 
	
	
	cout<< "Welcome to roulette. You may bet on Even,Odd, or Zero" << endl;
	cout<< "(use E, O, or Z.) Each bet is $5." << endl;
	cout<< "If you bet zero and win, you win $50." << endl;
	cout<< "You can choose Q to quit the game." << endl;
	cout<< "The game ends automotically if you run out of money." << endl;
	
	const int STARTING_MONEY = 100;
	const int BET_AMOUNT = 5;
	const int ZERO_WIN_AMOUNT = 50;
	char typeOfBet = ' ';
	cout<< endl;
	
	double moneyRemaining = STARTING_MONEY;
	double numberOfWins = 0;
	double numberOfLosses = 0;
	
	if (typeOfBet == 'E' || typeOfBet == 'e')
		{	
			cout<< wheelNumber << endl;
		}		
	else if (typeOfBet == 'O' || typeOfBet == 'o')
		{	
			cout<< wheelNumber << endl;
		}			
	else if (typeOfBet == 'Z' || typeOfBet == 'z')
		{
			cout<< wheelNumber << endl;
		}
			{
				cout <<"Bet on E)ven,O)dd,Z)ero,or Q)uit > ";
				cin >> typeOfBet;
			}
			
	
				{
					cout<< wheelNumber <<endl;
			
				}
		
	if ((wheelNumber == 0) && (typeOfBet == 0));
		((wheelNumber == 'O') && (typeOfBet == 'O'));
		((wheelNumber == 'E') != ('0') && (typeOfBet == 'E'));
		
		{
			if (wheelNumber == 0);
				{
					(ZERO_WIN_AMOUNT + moneyRemaining);
				}
				else
				{
					if (wheelNumber == typeOfBet);
						{
							(BET_AMOUNT + moneyRemaining);
							(numberOfWins += 1);
						}
							[
								cout<<"You win! You now have $ " << STARTING_MONEY << endl;
							]
				}
			}
		}
	}
		
		
		
				
	system("PAUSE");
	return 0;	
}

after i compile it,it tells me this:
63 C:\Dev-Cpp\Class Work\cit020_08_10_27\mok_hai_roulette2.cpp expected primary-expression before "else"
63 C:\Dev-Cpp\Class Work\cit020_08_10_27\mok_hai_roulette2.cpp expected `;' before "else"
63 C:\Dev-Cpp\Class Work\cit020_08_10_27\mok_hai_roulette2.cpp At global scope:
76 C:\Dev-Cpp\Class Work\cit020_08_10_27\mok_hai_roulette2.cpp expected declaration before '}' token .
please help, i just want to know why line "63" is not working?

What's a gibberish text after the last if! What a language are you using? It's not C++.
Moreover, it's not C# or Basic or.
Next time copy/paste someone else's code more accurately...

Well, I'm a noob myself so not really sure if I'm helping you or not but I guess I'll give it a shot.

First of all, you did declare typeOfBet and allocated memory for it but what's inside of that memory is just garbage, not related to what you want to store in there. So when you are doing comparison (checking whether it is E or e and etc)

Second, it says it's missing ';' on line 63. Why don't you go back to line 63 and see what's wrong with it?

if ((wheelNumber == 0) && (typeOfBet == 0));
		((wheelNumber == 'O') && (typeOfBet == 'O'));
		((wheelNumber == 'E') != ('0') && (typeOfBet == 'E'));

I'm gonna take a wild guess and say this is line 63. If it is, you want to change this to

if ((wheelNumber == 0) && (typeOfBet == 0))||
		((wheelNumber == 'O') && (typeOfBet == 'O'))||
		((wheelNumber == 'E') != ('0') && (typeOfBet == 'E'));

because by putting ";" at the end of those conditions, you are saying that is the end of a statement but it is not.

Well, there's more problems in the code but try that first and let us know what happens.

At a glance I saw more than 15 syntax errors. I'm way too lazy to point those all out... you have [] around a cout statement - that would probably make a compiler explode. You have ; all over the place where they shouldnt be. You have a few instances of a + operator with no left hand side to the equation. It seems as though someone different wrote the start and end of this code. Nobody likes a cheater.

no, im not a cheater.
its only my second week into C++ and its one of my assignment's.
im just having a hard time understanding the concept i guess.
well im going to try out freudin's idea and get back to everyone.
wish me luck.

Well, your syntax errors can be easily figured out from the errors. So do read the errors carefully, go back to your code, think about it a bit more, google the error message and if you still can't do it, then you post.

Let us know how it goes.

ok here's a question for you all,
how would i make the program to tell from even,odd and zero?
guess thats my main problem atm.
i figued that this would work but it dont.

char typeOfBet = (O)dd,(E)ven, and (Z)ero.

i know i need to declear them to something.
but how? im not sure how the program tells the difference between odd,even, or zero? from the random number generator thats 1-36.
hope you guys can help me out on this.

im not sure how the program tells the difference between odd,even, or zero? from the random number generator thats 1-36.
hope you guys can help me out on this.

if(Number%2==0) {
      cout << Number << " is even" << endl;
}
else {
      cout << Number << " is odd" << endl;
}

Number % 2 returns the rest of the division by 2 (it's called modulus).
Clearly if that rest is zero the number is even, otherwise, if the rest is 1, the number is odd.

Apart from this, you badly need to check the syntax ^^"

ok i've gotten the top part to work, but i cant figure out why i cant get this working.

here's what its suppose to do:

if (Wheel Number is zero and player chose Zero
OR Wheel Number is odd and player chose Odd
OR Wheel Number is even (but not zero) and player chose Even)
{
if (WheelNumber is zero)
{
Add ZERO_WIN_AMOUNT to Money Remaining
}
else
{
Add BET_AMOUNT to Money Remaining
}
Add one to Number of Wins
Congratulate player and display Money Remaining
}
else
{
Subtract BET_AMOUNT from Money Remaining
Add one to Number of Losses
Tell player “sorry” and display Money Remaining
}
}
else if (Type of Bet is not Q)
{
Print an error message for invalid input
}
}
Print the Money Remaining, Number of Wins, and Number of Losses


and here's my code so far for that part:

if ((wheelNumber = 0) && (bet = 0))
	{
	cout<< "You win! You now have $ " << moneyRemaining << endl;
	}
	((moneyRemaining += ZERO_WIN_AMOUNT) && (moneyRemaining += bet));
	else 
	{
	cout<< "Sorry, you lose. You now have $ "<< moneyRemaining << endl;
	}
	(moneyRemaining -= 1);
				
	else if ((wheelNumber == wheelNumber%2==1) && (bet == wheelNumber%2==1));
	{
	cout<< "You win! You now have $ " << moneyRemaining <<endl;
	}
	(moneyRemaining += bet);
			
	else if (wheelNumber != bet);
	{
	cout<< "Sorry, you lose. You now have $ " << moneyRemaining << endl;
	}
	(moneyRemaining -= 1);
	}

but its not doing what it needs to do. i know im not understanding something here, can someone point out what that might be?
i just want a hint on what im doing wrong.

can anyone tell me what im doing wrong here?
i really want to learn what im doing wrong here to fully grasp the concept to programing.

It seems you don't understand C++ syntax and flow of control semantics.
For example, the if statement selects one of two alternatives:

if (condition) {
   do it (if condition true)
   as usually there is a sequence of statements here
}
else {
   do that (if condition false)
   ...
}

For example:

if (wheelNumber == 0) // wheelNumber is zero)
{
    
   //Add ZERO_WIN_AMOUNT to Money Remaining
   moneyRemaining += ZERO_WIN_AMOUNT;
}
else // wheelNumber is not equal to zero
{
    // Add BET_AMOUNT to Money Remaining
    moneyRemaining += BET_AMOUNT;
}

There are lots of other misunderstanded C++ constructs in your code. For example, fantastic:

((moneyRemaining += ZERO_WIN_AMOUNT) && (moneyRemaining += bet));

No special assignment statements in C++. The simplest statement is so called expression statement:

any_expression ; // semicolon is a part of an expression stmt: terminator

No need to enclose every expression in parentheses: both expression and (expression) have the same effect.
Look at your expression now. It has a form expression1 && expression2. The && operator has two operands. The 1st is the result of expression1. If it's false then the 2nd operand does not evaluated at all. Of course, it does not bear a relation to your program logic. But formally it's a valid C++ expression statement...

I think you must get your textbook now and learn the very basic and simplest C++ syntax rules before typing help requests. I have never seen so surprising treatment of C++ language. Thank you, it's cool...

IMHO only...

Do check the syntax. When the compiler throws an error, DO READ THE ERROR. Error really tells you what exactly is wrong with your code.

if ((wheelNumber = 0) && (bet = 0))
	{
	cout<< "You win! You now have $ " << moneyRemaining << endl;
	}
	((moneyRemaining += ZERO_WIN_AMOUNT) && (moneyRemaining += bet)); //what is that statement doing outside of if bracket??

should be something like

if ((wheelNumber == 0) && (bet == 0))
{
	cout<< "You win! You now have $ " << moneyRemaining << endl;
	moneyRemaining += ZERO_WIN_AMOUNT;
        moneyRemaining += bet;
}

i'm just correcting your syntax, not logic. So if those two moneyRemaining statements needs to be done regardless of the if condition, then do it after the entire ifs, else ifs are done.

else 
	{
	cout<< "Sorry, you lose. You now have $ "<< moneyRemaining << endl;
	}
	(moneyRemaining -= 1);

why is this else here? because this is else, not else if, once it checks the first condition and if the first condition is not met, it will ALWAYS go to this else statement. It won't even check with other else if statements to see if the conditions are met. Do you see the flaw of logic here? Else statement should go after if and else ifs. Does that even compile in the first place? who knows. Again, what is that moneyRemaining statment doing outside of the bracket?? see what i said above.

else if ((wheelNumber == wheelNumber%2==1) && (bet == wheelNumber%2==1));
	{
	cout<< "You win! You now have $ " << moneyRemaining <<endl;
	}
	(moneyRemaining += bet);

that conditions inside else if is very wrong. Do you see that wheelNumber will never equal wheelNumber%2? (unless wheelNumber is 1, otherwise, for all other numbers, wheelNumber will never equal wheelNumber%2).

thanks for the help everyone, i'd finally got it.
instructor cleared up most of my confusions.
i just need to work on the bracket's on the if statements and indents.
it helps alot when i read and follow the Algorithm, i was all over the place.
but once again thanks for the help everyone.

i am working with conditional statements also having some problem with goto statement is there any way to replace it with some other statement.

Yes there is, but to figure out how to do it you ought to consider case by case.

Here's a simple example which asks the user to input an int, dimension, > 0 using goto:

int main(void) {
     int dimension = 0;
     askdimension:
     std::cout << "Please insert a dimension > 0" << std::endl;
     std::cin >> dimension;
     if(dimension<=0) {
          std::cout << "Error, dimension must be > 0. Retry. " << std::endl;
          goto askdimension;
    }
    return EXIT_SUCCESS;
}

and here's exactly the same thing written without the goto statement:

int main(void) {
    int dimension = 0;
    while(dimension<=0) {
        std::cout << "Please insert a dimension > 0" << std::endl;
        std::cin >> dimension;
        if(dimension<=0) {
            std::cout << "Error, dimension must be > 0. Retry. " << std::endl;
        }
    }
    return EXIT_SUCCESS;
}

In general, try to avoid the use of goto. There's always another, cleaner way to do it :)

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.