SRL Archive - General

I'm a noob


Rent

2012-11-13 18:23:05

this is my first thing i've ever tried.. i joined 1-2 hours ago, so i'm a bit stuck
program Test;

procedure RandomFunction;
var
i:integer;
begin
if (Random(100) < 60) then
Writeln('Congratulations you are a winner!')
else
Writeln('Aww, better luck next time!');

if (i> 60)then
begin
Writeln('Aww, better luck next time!');
end;
end;
begin
ClearDebug;
RandomFunction;
end.

^ whenever i play.. its shows 2 results, so i win and lose at the same time, just a lil help on how to resolve this would be great, ty !

Ian

2012-11-13 18:31:26

I just tried it out, it seems to work fine. What do you mean by it shows answers? Here's the debug from a few tries:
Aww, better luck next time!
Successfully executed.
Congratulations you are a winner!
Successfully executed.
Congratulations you are a winner!
Successfully executed.

Is this not what you wanted? :)

Albi

2012-11-13 18:34:18

Seems to work fine ^_^!
However when posting codes make sure to put it inside the
 
tags! It makes it more readable and keeps your threads tidier :)

Rent

2012-11-14 02:23:34

oh, okay, something must've gone wrong on my side, thanks for your answers, i'll try and find out how to use tags, =)

riwu

2012-11-14 02:38:35

What's this for?

if (i> 60)then
begin
Writeln('Aww, better luck next time!');
end;
0 is always smaller than 60 :rolleyes:

Sax

2012-11-14 04:32:28

you have to give i a value, otherwise it is always 0.

do this
i := Random(100); //Random 100 goes from 0 to 99 you can change this

So…

procedure RandomFunction;

var
i:integer;

begin
if (Random(100) < 60) then
Writeln('Congratulations you are a winner!')
else
Writeln('Aww, better luck next time!');

i := Random(100);
if (i> 60)then
begin
Writeln('Aww, better luck next time!');
end;
end;
begin
ClearDebug;
RandomFunction;
end.


you should add a Writeln if i < 60 too.

Laimonas171

2012-11-14 04:42:42

From: Rent
this is my first thing i've ever tried.. i joined 1-2 hours ago, so i'm a bit stuck
program Test;


^ whenever i play.. its shows 2 results, so i win and lose at the same time, just a lil help on how to resolve this would be great, ty !


you getting "two" answers because second if statement is always true. Because I is not defined and results is that i = 0, and i < 60 so you get second output. and that confuses you that you get '2' answers…



procedure RandomFunction;
var
i:integer;
begin
if (Random(100) < 60) then
Writeln('1.Congratulations you are a winner!'); // I added 1. as if sentence 1st one.
else
Writeln('1.Aww, better luck next time!');
// here you should (or above) define your i etc. i := 10, or i := random(100)
//
if (i > 60)then
begin
Writeln('2.Aww, better luck next time!');//So this one is second if sentence.
end;
end;
begin
ClearDebug;
RandomFunction;
end.

Imanoobbot

2012-11-14 04:48:21

From: Nirvana
you have to give i a value, otherwise it is always 0.

do this
i := Random(100); //Random 100 goes from 0 to 99 you can change this

So…

procedure RandomFunction;

var
i:integer;

begin
if (Random(100) < 60) then
Writeln('Congratulations you are a winner!')
else
Writeln('Aww, better luck next time!');

i := Random(100);
if (i> 60)then
begin
Writeln('Aww, better luck next time!');
end;
end;
begin
ClearDebug;
RandomFunction;
end.


you should add a Writeln if i < 60 too.




Haha, I like that. Writing an auto Dicing calculator is that easy. :P

Rent

2012-11-17 07:16:28

ty guys