<mosaic.cnfolio.com>
PROGRAM
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <time.h>
4. #include <string.h>
5.
6. /*
7. START
8.    Obtain 4 numbers and the amount being betted on each number
9.    IF the numbers being betted on are positive integers in the range 0 to 36 or is 00 AND
10.       the value of the bets are greater than £0.00
11.          THEN
12.             Obtain a random number in the range 0 to 37
13.             IF the random number matches an input
14.                THEN
15.                   Display the random number obtained which is the winning number
16.                   multiply the money betted on the winning number by 35 for the profit, multiply the input amout by 36 for revenue
17.                   multiply the money betted on the losing numbers by -1 for the profit and make the revenue for each equal to zero
18.                   Display all the numbers that were betted on, how much was betted on each number, the revenue and profit for each bet
19.                   Display the net profit
20.                ELSE
21.                   IF the random number doesn't match any of the numbers that were betted on
22.                      THEN
23.                         multiply the money betted on the numbers by -1 for profit and make the revenue equal to zero
24.                         Display the random number obtained which is the winning number
25.                         Display all the numbers that were betted on, how much was betted on each number and the revenue and profit for each bet
26.                         Display the net profit which is the sum of the individual profits
27.                      END IF
28.              END IF
29.    ELSE
30.       IF a number being betted on is not in the range 0 to 36 or 00
31.          THEN
32.             Display message that numbers being betted on must be integers in the range from 0 to 36 or 00
33.       END IF
34.       IF Value of a bet is not a positive number
35.          THEN
36.             Display error message that the value placed on a bet has to be greater than £0.00
37.       END IF
38. END
39. */
40.
41. char DZ[] ="00" ;     // DZ is Double zero
42. char a1={ '\0' } ; // I am taking the numbers being betted on as strings. this is the first string
43. char b1={ '\0' } ; // second number being betted on
44. char c1={ '\0' } ; // third number being betted on
45. char d1={ '\0' } ; // fourth number being betted on
46.
47. float a, b, c, d ;                     // In my calculations, I will not be using the characters above. I will use a for a1, b for b1 etc.
48. float Am, Aa, Bm, Bb, Cm, Cc, Dm, Dd ; // Am, Bm Cm and Dm are the amounts betted on a, b, c and d respectively  Aa is the profit for a
49. float aP, bP, cP, dP ;                 // aP = Payout for a; bP = Payout for b; cP = Payout for c; dP = Payout for d;
50. int   N ;                              // N is The winning number
51.
52. int main( void )
53. {
54.    scanf( "%s", &a1 ) ; //First number being betted on
55.    scanf( "%f", &Am ) ; //Amount being being betted on the first number
56.    scanf( "%s", &b1 ) ; //Second number being betted on
57.    scanf( "%f", &Bm ) ; //Amount being being betted on the second number
58.    scanf( "%s", &c1 ) ; //Third number being betted on
59.    scanf( "%f", &Cm ) ; //Amount being being betted on the third number
60.    scanf( "%s", &d1 ) ; //Fourth number being betted on
61.    scanf( "%f", &Dm ) ; //Amount being being betted on the fourth number
62.
63.   if( strncmp(DZ,a1,2) == 0 )
64.      { a=0.5 ; }             // If the character a1 is 00, I make the number a = 0.5 so it passes the next test condition
65.   else{a=atoi(a1);}          // If a1 is a charcter different from 00, e.g 14, I make a equal to the integer
66.
67.   if( strncmp(DZ,b1,2) == 0)
68.      { b=0.5 ; }             // If the character b1 is 00, I make the number b = 0.5 so it passes the next test condition
69.   else{b=atoi(b1);}          // If b1 is a charcter different from 00, e.g 14, I make b equal to the integer
70.
71.   if( strncmp(DZ,c1,2) == 0)
72.      { c=0.5 ; }             // If the character c1 is 00, I make the number c = 0.5 so it passes the next test condition
73.   else{c=atoi(c1);}          // If c1 is a charcter different from 00, e.g 14, I make c equal to the integer
74.
75.   if( strncmp(DZ,d1,2) == 0)
76.      { d=0.5 ; }             // If the character d1 is 00, I make the number d = 0.5 so it passes the next test condition
77.   else{d=atoi(d1);}          // If d1 is a charcter different from 00, e.g 14, I make d equal to the integer
78.
79.
80.  if( a>=0 && a<=36 && b>=0 && b<=36 && c>=0 && c<=36 && d>=0 && d<=36 && Am>0 && Bm>0 && Cm>0 && Dm>0 )
81.     // All the numbers bewing betted on must be in the range from 0 to 36 or 00  The bet values have to be greater than £0.00
82.  {
83.     srand( time( NULL ) ) ;
84.     N = rand( ) % 38 ;
85.
86.     if(a==0.5) { a=37.0 ;} //If someone enters 00, to differentiate it from 0, I first made it 0.5 instead of 37 so it passes the last if statement
87.     if(b==0.5) { b=37.0 ;} //After 00 which i made 0.5 passes the if statement, I want to treat it as 37 to allow calculations
88.     if(c==0.5) { c=37.0 ;}
89.     if(d==0.5) { d=37.0 ;}
90.
91.
92.     if( N==a ) {  Aa = 35*Am ; aP = 36*Am ;} //Aa is the profit for a, and aP is the payout for a
93.     else { Aa= -Am ; aP=0 ; }
94.
95.     if( N==b ) {  Bb = 35*Bm ; bP = 36*Bm ;} //Bb is the profit for b, and bP is the payout for b
96.     else { Bb = -Bm ; bP=0 ;}
97.
98.     if( N==c ) {  Cc = 35*Cm ; cP = 36*Cm ;} //Cc is the profit for c, and cP is the payout for c
99.     else {Cc = -Cm ; cP=0 ;}
100.
101.     if( N==d ) {  Dd = 35*Dm ; dP = 36*Am ;} //Dd is the profit for d, and dP is the payout for d
102.     else { Dd=-Dm ; dP=0 ;}
103.
104.    if( N==37 ){printf( "The winning number is 00\n\n" );}
105.    else{ printf( "The winning number is %d \n\n", N ); }
106.    printf( "You bet £%.2f on %s, your revenue is £%.2f and profit is £%.2f \n", Am, a1, aP, Aa ); // The revenue is the payout
107.    printf( "You bet £%.2f on %s, your revenue is £%.2f and profit is £%.2f \n", Bm, b1, bP, Bb ); // If I invest £1.00 and I get £2.00 back
108.    printf( "You bet £%.2f on %s, your revenue is £%.2f and profit is £%.2f \n", Cm, c1, cP, Cc ); // My payout||revenue is £2.00 but
109.    printf( "You bet £%.2f on %s, your revenue is £%.2f and profit is £%.2f \n\n", Dm, d1, dP, Dd ); // My profit is £1.00
110.    printf( "Your net profit is £%.2f \n", Aa+Bb+Cc+Dd );
111.
112.    a=0.5; b=0.5; c=0.5 ; d=0.5 ;//When 00 is entered, I convert a, b, c, d to 37, if I leave it that way, the next error message will be displayed
113.
114.   }
115.    if( a<0 || b<0 || c<0 || d<0 || a>36 || b>36 || c>36 || d>36 )   // Numbers being betted on must be in the range from 0 to 36
116.     { printf( "\n Make sure that all input numbers are in the range from 0 to 36. \n" ) ;}
117.    if( Am<0 || Bm<0 || Cm<0 || Dm<0 )    // Bet values have to be greater than £0.00
118.     { printf( " Make sure that the values placed on all bets are greater than £0.00 \n" ); }
119. }