Some feedback/help on my code

This is an example on the code is suppose to output things:

• Player bets $10 on Crown and rolls one Crown: gets $10 bet back plus wins an additional
$10.
• Player bets $10 on Diamond and rolls two Diamonds: gets $10 bet back, plus wins an
additional $20.
• Player bets $10 on Anchor and rolls three Anchors: gets $10 bet back, plus wins an
additional $30.
• Player bets $10 on Spade and rolls no Spades: loses the $10 bet.

-----------------------------------------------------------------------------
my code:

if (symbol == dice1 || symbol == dice2 || symbol == dice3){
moneyWon = moneyWon + bet + (bet *3);
balance = balance + moneyWon;
cout << "You won: $" << moneyWon << endl;
cout << "Your balance is: $" << balance << endl;
}
else if (symbol == dice1 || symbol == dice2 || symbol != dice3){
moneyWon = moneyWon + bet + (bet *2);
balance = balance + moneyWon;
cout << "You won: $" << moneyWon << endl;
cout << "Your balance is: $" << balance << endl;
}
else if (symbol == dice1 || symbol != dice2 || symbol != dice3){
moneyWon = moneyWon + bet + (bet *1);
balance = balance + moneyWon;
cout << "You won: $" << moneyWon << endl;
cout << "Your balance is: $" << balance << endl;
}
else if ( symbol != dice1 && symbol == dice2 && symbol != dice3){
moneyWon = bet;
balance = balance - moneyWon;
cout << "You lost: $" << moneyWon << endl;
cout << "Your current balance is: $" << balance << endl;
}
-------------------------------------------------------------------------------
Im having trouble coding this part of the program and would like some feedback on what I can do.
If symbol is a string, you need to put dice1 in quotes.
Not being able to see the rest of your code, I assume that's all the help you need.
this is the full code
-----------------------------------------
#include <iostream>

#include <iomanip>

#include<cstdlib>

#include<time.h>

#include<string>

using namespace std;

int getRandomNum(int lowRange, int highRange);

int main(){

srand(static_cast<int> (time(NULL)));

int bet; // money betting

int balance; //players balance

int symbol; // symbol chosen

int rolled;

int moneyWon = 0;

int dice1, dice2, dice3;

string dice11, dice22, dice33;

bool balanceCheck = false;

int count; // Number of times rolled

cout << "Welcome to the Crown and Anchor Game" << endl;

cout << "Good Luck!!!!!" << endl;

cout << "How much money will you play with? $";

cin >> balance;

cout << endl;

cout << "****************************************************" << endl;

cout << endl;

while (!balanceCheck){

cout << "Enter your bet: $";

cin >> bet;

if (bet > balance){

cout << "Please bet of $" << balance << " or lower." << endl;

balanceCheck = false;

}

else{

balanceCheck = true;

}

}

cout << "Choose a character. Enter: " << endl;

cout << " 1 for Heart" << endl;

cout << " 2 for Crown" << endl;

cout << " 3 for Diamond" << endl;

cout << " 4 for Club" << endl;

cout << " 5 for Anchor" << endl;

cout << " 6 for Spade" << endl;

cout << "...Your choice: ";

cin >> symbol;

cout << endl;

for (count = 0; count < 1; ++count){

rolled = getRandomNum(1, 6);

switch (rolled){

case 1:

dice1 = 1;

dice11 = "Heart";

break;

case 2:

dice1 = 2;

dice11 = "Crown";

break;

case 3:

dice1 = 3;

dice11 = "Diamond";

break;

case 4:

dice1 = 4;

dice11 = "Club";

break;

case 5:

dice1 = 5;

dice11 = "Anchor";

break;

case 6:

dice1 = 6;

dice11 = "Spade";

break;

}

rolled = getRandomNum(1, 6);

switch (rolled){

case 1:

dice2 = 1;

dice22 = "Heart";

break;

case 2:

dice2 = 2;

dice22 = "Crown";

break;

case 3:

dice2 = 3;

dice22 = "Diamond";

break;

case 4:

dice2 = 4;

dice22 = "Club";

break;

case 5:

dice2 = 5;

dice22 = "Anchor";

break;

case 6:

dice2 = 6;

dice22 = "Spade";

break;

}

rolled = getRandomNum(1, 6);

switch (rolled){

case 1:

dice3 = 1;

dice33 = "Heart";

break;

case 2:

dice3 = 2;

dice33 = "Crown";

break;

case 3:

dice3 = 3;

dice33 = "Diamond";

break;

case 4:

dice3 = 4;

dice33 = "Club";

break;

case 5:

dice3 = 5;

dice33 = "Anchor";

break;

case 6:

dice3 = 6;

dice33 = "Spade";

break;

}

}

cout << "Dice Rolled: " << dice11 << " " << dice22 << " " << dice33 << endl;

cout << endl;

if (symbol == dice1, symbol == dice2, symbol == dice3){

moneyWon = moneyWon + bet + (bet * 3);

balance = balance + moneyWon;

cout << "You won: $" << moneyWon << endl;

cout << "Your balance is: $" << balance << endl;

}

else if (symbol == dice1, symbol == dice2, symbol == dice3){

moneyWon = moneyWon + bet + (bet * 2);

balance = balance + moneyWon;

cout << "You won: $" << moneyWon << endl;

cout << "Your balance is: $" << balance << endl;

}

else if (symbol == dice1, symbol == dice2, symbol == dice3){

moneyWon = moneyWon + bet + (bet * 1);

balance = balance + moneyWon;

cout << "You won: $" << moneyWon << endl;

cout << "Your balance is: $" << balance << endl;

}

else if (symbol == dice1, symbol == dice2, symbol == dice3){

moneyWon = bet;

balance = balance - moneyWon;

cout << "You lost: $" << moneyWon << endl;

cout << "Your current balance is: $" << balance << endl;

}

}

int getRandomNum(int lowRange, int highRange)

{

int randNum;

randNum = (rand() % (highRange - lowRange + 1)) + lowRange;

return randNum;

}
http://www.cplusplus.com/articles/z13hAqkS/


Please always use code tags, and indent the code.

If you do that, we can have line numbers, keyword highlighting, and we can run the code right here with the gear icon. All these things make life much easier.

if (symbol == dice1, symbol == dice2, symbol == dice3){

You need either && or || instead of those commas.
Topic archived. No new replies allowed.