home *** CD-ROM | disk | FTP | other *** search
- PROGRAM COINS_PROGRAM;
- (*************************************************************************)
- (*************************************************************************)
- (** Microcomputer Application and Design I **)
- (** Section 1 **)
- (** Assignment 5 **)
- (*************************************************************************)
- (**** ***)
- (**** This Program Will Simulate a coin toss twenty times and count ***)
- (**** the number of heads and the number of tails thrown. ***)
- (**** ***)
- (*************************************************************************)
- (*************************************************************************)
-
- Uses Crt;
- Var
- QuitFlag : Boolean;
- HeadsCount,
- TailsCount,
- Ran_Seed,
- Count : Integer;
- Number : Real;
-
-
- (******************************************************)
- (* Quit Procedure *)
- (******************************************************)
- (* This Procedure Procedure will display the *)
- (* Quit or continue option. *)
- (******************************************************)
- PROCEDURE QuitProc(Var QuitFlag: Boolean);
-
- Var
- P : Char;
-
- Begin
- WriteLn;
- WriteLn;
- WriteLn;
- TextColor(LightBlue);
- Write(' Please enter ');
- TextColor(LightRed + Blink);
- Write('Q');
- TextColor(LightBlue);
- Write(' to quit or ');
- TextColor(Red + Blink);
- Write('<Enter>');
- TextColor(LightBlue);
- Write(' to continue: ');
- Read(p);
- TextColor(LightBlue);
-
- P := UpCase(P);
-
- If (P = 'Q') Then
- QuitFlag := True
- Else
- QuitFlag := False;
- End;
-
- (******************************************************)
- (* Title Screen Procedure *)
- (******************************************************)
- (* This Procedure Prints The Title Screen. *)
- (******************************************************)
- PROCEDURE TitleScreen(Var QuitFlag:Boolean);
-
- Begin
- ClrScr;
- TextColor(Cyan);
- WriteLn;
- WriteLn(' Programmer: C. Ben Davis');
- WriteLn(' SS# 361-52-5415');
- WriteLn(' Class: ACS 255');
- TextColor(LightBlue);
- WriteLn;
- WriteLn;
- WriteLn(' This program will simulate a coin toss twenty times, and');
- WriteLn(' count the number of heads and the numbers of tails thrown.');
- WriteLn;
- WriteLn;
- WriteLn;
- End;
-
- (******************************************************)
- (* Print Graph Procedure *)
- (******************************************************)
- (* This Procedure Prints the graph to the screen. *)
- (******************************************************)
- PROCEDURE PrintGraph;
-
- Begin
- WriteLn;
- WriteLn;
- WriteLn;
- WriteLn;
- TextColor(LightBlue);
- Write('HEADS: ');
- TextColor(DarkGray);
-
- While HeadsCount > 0 Do
- Begin
- Write('▓');
- HeadsCount := HeadsCount - 1
- End;
-
- TextColor(LightBlue);
- WriteLn;
- WriteLn;
- Write('TAILS: ');
- TextColor(LightGray);
-
- While TailsCount > 0 Do
- Begin
- Write('▒');
- TailsCount := TailsCount - 1
- End;
- TextColor(LightGreen);
-
- End;
-
- (******************************************************)
- (* Flip Coin Procedure *)
- (******************************************************)
- (* *)
- (* This Procedure Procedure flips the coin 20 times. *)
- (* *)
- (******************************************************)
- PROCEDURE FlipCoin(var QuitFlag:Boolean;Ran_Seed:Integer);
-
- Begin
- HeadsCount := 0;
- TailsCount := 0;
- Count := 0;
- Randomize;
- RandSeed := Ran_Seed;
- While (Count < 20) do
- Begin
- Number := Random;
- If (Number < 1/2) or (Number = 1/2) Then
- TailsCount := TailsCount +1 {Writeln (' Tails')}
- Else
- If Number > 1/2 Then
- HeadsCount := HeadsCount + 1 {Writeln(' Heads')}
- Else
- If Number > 1 Then
- Writeln( ' ERROR');
- Count := Count +1;
- End;
- WriteLn;
- WriteLn;
- TextColor(White);
- WriteLn('Number of Tails Thrown: ',TailsCount);
- WriteLn('Number of Heads Thrown: ',HeadsCount);
- PrintGraph;
-
- QuitProc(QuitFlag);
- End;
-
- (****************************************************************************)
- (* MAIN PROCEDURE *)
- (****************************************************************************)
-
- Begin
- QuitFlag := False;
- TitleScreen(QuitFlag);
- QuitProc(QuitFlag);
-
-
- While (QuitFlag = False) Do
- Begin
- Clrscr;
- TextColor(LightGray);
- Write('Enter a Number Between 1 and 100: ');
- Readln(Ran_Seed);
- If Ran_Seed > 100 then
- Begin
- TextColor(Yellow);
- WriteLn(' Please Choose A Number Less than or equal to 100!');
- Readln;
- End
- Else
- FlipCoin(QuitFlag,Ran_Seed);
- End;
-
- ClrScr;
- Writeln;
- WriteLn;
- WriteLn;
- TextColor (LightGray);
- Write (' Give Me an A+!!!!');
- End.
-