Created
December 3, 2019 07:55
-
-
Save cacharle/fed2ef9d566cc924886a3db2ec48c555 to your computer and use it in GitHub Desktop.
tp craps openclassrooms ada course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Numerics.Discrete_random; | |
with Ada.Text_io; use Ada.Text_io; | |
with Ada.Integer_Text_io; use Ada.Integer_Text_io; | |
procedure Craps is | |
subtype Interval is Integer range 1..6; | |
package IntRandom is new Ada.Numerics.Discrete_random(Interval); | |
use IntRandom; | |
gen: Generator; | |
function Roll_dice return Integer is | |
begin | |
return random(gen) + random(gen); | |
end Roll_dice; | |
bet: Integer; | |
money: Integer := 50; | |
roll: Integer; | |
point_roll: Integer; | |
begin | |
reset(gen); | |
while money > 0 loop | |
put("You currently have "); | |
put(money, 0); | |
put_line("$"); | |
put("Input your bet: "); | |
get(bet); | |
skip_line; | |
if bet >= 1 and bet <= money | |
then | |
money := money - bet; | |
put("Your dice sum is: "); | |
roll := Roll_dice; | |
put(roll, 0); | |
new_line; | |
case roll is | |
when 7 | 11 => put_line("You won"); | |
money := money + 2 * bet; | |
when 2 | 3 | 12 => put_line("craps"); | |
when others => put_line("Point is on"); | |
loop | |
point_roll := roll_dice; | |
put("Point roll: "); | |
put(point_roll); | |
new_line; | |
if point_roll = 7 | |
then money := money - 2 * bet; | |
end if; | |
exit when point_roll = roll or point_roll = 7; | |
end loop; | |
money := money + 2 * bet; | |
end case; | |
else | |
put_line("Your bet is Incorrect"); | |
end if; | |
new_line; | |
new_line; | |
end loop; | |
end Craps; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment