<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Start Program
  3.     Enter starting money
  4.     Scan input (%f for double)
  5.     Printf output
  6.  
  7.     User Inputs bet money
  8.     Compiler scans the input
  9.     Printf output
  10.  
  11.     For loop (x4) for 4 bets.
  12.     Make 00 a char string with 2 character
  13.     String = integer
  14.  
  15.     User enters bet
  16.     Scanf as string
  17.     Print the output
  18.  
  19.     Random number generator from 0-37 rand = int
  20.     if
  21.             Random number = 37
  22.             printf = 00
  23.                 Else
  24.                     printf "ball has landed on ..."
  25.                    
  26.     If random number == bet number
  27.         then its win (balance and profit * 35)
  28.                 Else its a loss balance +- moneybet
  29.                
  30. END PROGRAM
  31. */
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <time.h>
  36.  
  37.  
  38. //intergers for betting
  39. double moneybet;
  40. double balance;
  41. double profit;
  42. double loss;
  43.  
  44. int main(){
  45.     srand(time(0));
  46.     profit = 0;
  47.     loss = 0;
  48.  
  49.     //enter money you want to start with
  50.     printf("Enter the amount of money you are starting with:"); /* User enter the amount to start the game with*/
  51.     scanf("%lf", &balance); /*scans the users input*/
  52.     printf("\nYou have entered the game with %f, goodluck.\n\n",  balance); /*Displays the in-putted values*/
  53.  
  54.     printf("Enter the amount you want to bet: "); /* User now enters the amount of money to use for betting*/
  55.     scanf("%lf", &moneybet);/* Compiler scans the in-putted values*/
  56.     printf("You have put down a %f bet. High risk, high payout! (35 to 1)\n", moneybet);/*displays the in-putted values.*/
  57.  
  58.     //roulette loop 4 times
  59.     for (int i = 0 ; i < 4 ; i++){
  60.         char tempBetStr[2]; //2 digit number so need string with length 2
  61.         int tempBetNum;
  62.     //Print and Scan as String for 00     
  63.         printf("Enter bet %i: ", i+1);
  64.         scanf("%s",tempBetStr); //input must be string so we can differentiate between 0 and 00
  65.         printf("You have selected the following number: %s.\n", tempBetStr);
  66.        
  67.         int randomInt = (rand() % 38); //random number 0-37
  68.         if (randomInt == 37){
  69.             printf("Ball %i has landed on: 00. You betted on %s\n", i+1, tempBetStr);
  70.         }else{
  71.             printf("Ball %i has landed on: %i. You betted on %s\n", i+1, randomInt, tempBetStr);
  72.         }
  73.  
  74.         if ((tempBetStr[0] == '0') && (tempBetStr[1] == '0')){
  75.             tempBetNum = 37; //double zero at position 37
  76.         }else{
  77.             tempBetNum = atoi(tempBetStr); //atoi = converts string to integer
  78.         }
  79.  
  80.         if (randomInt == tempBetNum){ //Checks if the values of two operands are equal or not. If yes, then the condition becomes true.
  81.             profit += moneybet * 35.0;
  82.             balance += moneybet * 35.0;
  83.             printf("Winner winner! You now have %f in your pocket!\n", balance);
  84.         }else{
  85.             loss += moneybet;
  86.             balance -= moneybet;
  87.             printf("Sorry, you lost %f. Your new balance is %f.\n", moneybet, balance);
  88.         }
  89.         printf("\n");
  90.     }
  91.  
  92.     //finish
  93.     printf("Profit: %f, Loss: %f\n", profit, loss);
  94. }