Results 1 to 7 of 7

Thread: help!

  1. #1

    help!

    I am a complete newbie to the world of programming and I need some help in the creation of this program. This is a homework assignment, I just need someone to tell me what to put in the procedures part because it seems like he wants most of the commands in the main program and there;s nothing left for the procedures. Unless I'm looking at this the wrong way and he posted the procedure instead and it's not the main program...please help!!!

    [pascal]program evenGame;
    var bet: integer; { the amount bet by the user }
    amount: integer; { the amount won or lost }
    num: integer; { the random number }
    win: boolean; { win = true or false }

    { insert your "even" procedure here }

    begin
    write('How much would you like to bet? ');
    readln(bet);

    { Add 2 lines here to }
    { create a random number, 1 to 36 }

    even(num,bet,win,amount);

    writeln('The number is: ', num);

    { Add an If Statement which uses writeln statements }
    { to print a winning or losing message. }
    { Hint: test the value of the "win" variable. }

    end.[/pascal]

    [size=9px]BBCode pascal tags added by moderator during clean-up.[/size]

  2. #2

    ok i got this far

    alright it turns out that it was the beginning of a procedure. This is as far as I got and it says that my parameters (win, amount, bet, num) "does not seem to be initialzed." Why is that? Can someone point out what I did wrong?

    [pascal]program evenGame;
    var bet: integer; { the amount bet by the user }
    amount: integer; { the amount won or lost }
    num: integer; { the random number }
    win: boolean; { win = true or false }

    procedure even(bet: integer; num: integer; amount: integer; win: boolean);
    begin
    write('How much would you like to bet? ');
    readln(bet);

    randomize;
    num := 1 + random(36);

    even(num,bet,amount,win);
    writeln('The number is: ', num);
    read(num);
    if (num mod 2 = 0) then
    writeln('You win ', bet*3)
    else if (num mod 2 = 1) then
    writeln('You lose');
    end;

    begin
    even(num,bet,amount,win);
    end.[/pascal]

    [size=9px]BBCode pascal tags added by moderator during clean-up.[/size]

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    help!

    Hi ic3_man, welcome to PGD.

    Just a couple of recommendation to help you out right off the bat. First, try using the Pascal BBCode tags provided in your reply Toolbar. it'll make the code clearer and easier to view.

    Second, I'd suggest you find a good book on the basics of Pascal or better yet, Object Pascal. Whats the difference? One specifically is a more current, Object Oriented Programming (OOP) language and the other is the older, non-OOP version of the same language. As an alternative you can also find some good materials in the PGD Library on the Pascal langage it's self. In fact I'd bookmark it, as you are a beginner these resources will be a great place to get started with.

    Lastly, if you are using something like Delphi that has helpfiles included, I'd strongly recommend getting used to the language reference help files. I practically learned most of what I know about the language using Turbo Pascal 7 and Delphi 3 help files.


    As for your problem, I'd have gone with a different naming scheme for your procedure's parameters. Because what you have done is altered the local variables instead of the global ones that will stick around after the procedure has closed.

    OR you could have done this instead:

    [pascal]procedure even(var bet, num, amount: integer; var win: boolean);[/pascal]

    Which will allow the procedure to alter the variables passed to it while calling it.

    Hope this helps. BTW, what compiler(s) are you using?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    ok

    It turns out that was the problem and I redid the parameters like you did. Now I just have a problem with the program not going on past 'How much would you like to be?' It's looping, but I think I can figure it out from here. Thanks!

  5. #5

    help!

    Well despite the fact that it means you would be cheating on your homework, a little help never hurt anyone.

    Here's the working code.

    [pascal]
    program EvenGame;

    { Global Variables }
    var
    Amount: Integer;
    Quit: String;

    procedure Even;
    { Local Variables }
    var
    Bet: Integer;
    Num: Integer;
    begin
    Write('How much would you like to bet? ');
    ReadLn(Bet);
    If Bet<Amount Then
    begin
    Amount:=Amount-Bet;
    Num := 1 + Random(36);
    WriteLn('The number is: ', num);
    { If we win }
    If (Num Mod 2 = 0) then
    begin
    { The multiplier here could be anything but since this is a game of 50/50 chance, it would be odd to have anything other than a double or nothing payout }
    WriteLn('You win ', Bet*2) ;
    Amount:=Amount+(Bet*2);
    { If we lose }
    end else
    WriteLn('You lose, good day sir!');
    end Else
    WriteLn('You do not have enough money to cover the bet');
    end;

    begin
    Randomize;
    Amount:=100;
    WriteLn('You now have ',amount);
    Repeat
    Even;
    WriteLn('You now have ',amount);
    WriteLn('Would you like to quit? [Y] or [N]');
    ReadLn(Quit);
    Until (Quit='Y') or (Quit='y');
    end.
    [/pascal]

    Aah, this takes me back. While I haven't compiled this code I have read it through thoroughly and I'm confident it will work first time and if it doesn't Im sure a few of the regulars will soon let me know and I will be laughed off the boards.

    BTW welcome to PGDev.
    Isometric game development blog http://isoenginedev.blogspot.com/

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    help!

    It's only cheating if you don't learn anything. ...or there's money involved, which I doubt.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7

    help!

    Thanks and I found the flaws in my current program. And thank you for welcoming me to the community. I'll see you guys around!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •