To be honest, you don't use braces when you should. This is a problem, because you also don't use good indent style. Once it's straightened out, you can see that the majority of output and other stuff happens whether you are in the right bet mode or not. You also print a message like you lost whether you did or not.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
int betmode;
int straightbet, cashbet;
int number;
int balance;
char colorbet, R, B;
int i, n;
//welcome and tittle
printf("******************************************************************\n");
printf("******************************************************************\n");
printf("Welcome to my Roulette program.");
printf("\n******************************************************************\n");
printf("******************************************************************\n");
//Instructions for the game
printf("\nEntering the casino, you have $100\n");
printf("There are 2 types of bets you can make\n\n");
printf("1) Straight-up bet: Choose a single number. High risk, high payout! (35 to 1)\n\n");
printf("2) Red or black: Choose a colour.(1 to 1)\n Red numbers are 1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36\n Black numbers are 2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35\n\n");
//Select game mode:
printf("\nPlease select your preferred type of bet:");
scanf("%d", &betmode);
balance=100;
//Loop to keep game going as long as you have cash
if (betmode==1) //Straight bets
printf("\nGoing for the big money, eh?\n Enter a number between 1-36 you'd like to bet on> ");
scanf("%d", &straightbet);
printf("Now how much money are you willing to risk? Payout is 35 to 1> ");
scanf("%d", &cashbet);
printf("\nYou have bet $%d on the number %d", cashbet, straightbet);
printf("\nGoodluck. Here are the Results\n");
n = 4;
/* Intializes random number generator */
srand((unsigned) time(NULL));
/* Print 5 random numbers from 0 to 49 */
for( i = 0 ; i < n ; i++ )
{
printf("%d\n", rand() % 36);
}
if (number==straightbet)
{
balance += (cashbet*35);
printf("Winner Winner! You now have $%d in your pocket", balance);
}
else
balance -= cashbet;
printf("Sorry. You've lost $%d. Your new balance is $%d", cashbet, balance);
}]
See how for if (and in one place, else) the next line is indented? That is the default behavior for if-else: the next line is all that is impacted by the decision. If you have multiple lines of code that should run if something is true, or lines that should run only if something is false, then you need to put those lines in a big curly brace block. One opening brace for where the block starts and one closing brace for where the block ends.
I have a hard time believing that the compiler didn't complain about the stray ] in your program on the last line, so that might have been a copying error, but if it's in the source, remove it.
One of the biggest problems with betting is that nothing is saved to number. You print four random numbers and do nothing else with them. They aren't saved anywhere. The easiest change would be to write:
Code:
for (i = 0 ; i < n ; i++)
{
number = rand() % 36 + 1;
printf("%d\n", number);
if (number == straightbet)
{
balance += (cashbet * 35);
printf("Winner winner! You now have $%d in your pocket!\n", balance);
}
else
{
balance -= cashbet;
printf("Sorry, you lost $%d. Your new balance is $%d.\n", cashbet, balance);
}
}
Now you can process all four bets.
I hope this shows you indent style matters.