Recent

Author Topic: HELP CREATE!!  (Read 2419 times)

ilhamrizki25

  • Newbie
  • Posts: 5
HELP CREATE!!
« on: September 07, 2018, 06:23:10 am »
So, I've been trying to create these 2 programs for 4 hours straight. Can someone help me??

1. Create a program that accepts input integers x and y which state the coordinates of the point <x, y>. Declare a boolean variable that will be true if the point is located on the X or Y axis.
** instructions: just use a logical operator, not using a case analysis scheme

2. Create a program that accepts input 4 integer numbers x1, y1, x2, y2 which state 2 points, namely <x1, y1> and <x2, y2>. Calculate the distance between the two points.
** instructions: do not use record type data

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: HELP CREATE!!
« Reply #1 on: September 07, 2018, 06:35:49 am »
So, I've been trying to create these 2 programs for 4 hours straight. Can someone help me??
Was that enough time for you to write some code you could post or do you need more time ?
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ilhamrizki25

  • Newbie
  • Posts: 5
Re: HELP CREATE!!
« Reply #2 on: September 07, 2018, 06:39:08 am »
So, I've been trying to create these 2 programs for 4 hours straight. Can someone help me??
Was that enough time for you to write some code you could post or do you need more time ?

I've been stuck on number 1 and these are the only program I get :

Code: Pascal  [Select][+][-]
  1. Program soal1;
  2. {Program ini berfungsi untuk menerima input koordinasi titik x dan y yang dimana jika titik tersebut terletak pada sumbu x atau y akan dinyatakan true.}
  3.  
  4. VAR
  5.         X,Y : boolean;
  6.  
  7. Begin
  8.         writeln('Masukkan Koordinat X = ',X);
  9.         writeln('Masukkan Koordinat Y = ',Y);
  10.         (X=0) OR (Y=0) := true;
  11.         (X<>0) OR (Y<>0) := false;
  12.  
  13.  
  14. end.
  15.  

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: HELP CREATE!!
« Reply #3 on: September 07, 2018, 06:49:01 am »
I've been stuck on number 1 and these are the only program I get :

Code: Pascal  [Select][+][-]
  1. Program soal1;
  2. {Program ini berfungsi untuk menerima input koordinasi titik x dan y yang dimana jika titik tersebut terletak pada sumbu x atau y akan dinyatakan true.}
  3.  
  4. VAR
  5.         X,Y : boolean;
  6.  
  7. Begin
  8.         writeln('Masukkan Koordinat X = ',X);
  9.         writeln('Masukkan Koordinat Y = ',Y);
  10.         (X=0) OR (Y=0) := true;
  11.         (X<>0) OR (Y<>0) := false;
  12.  
  13.  
  14. end.
  15.  
you need to add two readln statements one after each writeln to read the users input and you need to define the boolean variable to hold the answer to your comparison eg
Code: Pascal  [Select][+][-]
  1. Program soal1;
  2. {Program ini berfungsi untuk menerima input koordinasi titik x dan y yang dimana jika titik tersebut terletak pada sumbu x atau y akan dinyatakan true.}
  3.  
  4. VAR
  5.         X,Y : Integer;
  6.         OnAxis:Boolean;
  7. Begin
  8.         writeln('Masukkan Koordinat X = ');
  9.         readln(X);
  10.         writeln('Masukkan Koordinat Y = ',Y);
  11.         OnAxis := (X=0) OR (Y=0);
  12.         //(X<>0) OR (Y<>0) := false; this is not needed
  13. end.
  14.  
complete the rest.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: HELP CREATE!!
« Reply #4 on: September 07, 2018, 07:05:00 am »
Maybe something like this:

Code: Pascal  [Select][+][-]
  1. program CoordinateTest;
  2.  
  3. uses
  4.   Crt;
  5.  
  6. var
  7.   X, Y, i : Integer;
  8.   XisZero : Boolean;
  9.   YisZero : Boolean;
  10.  
  11. begin
  12.  
  13.   ClrScr;
  14.   WriteLn('Please provide a value for X:');
  15.   ReadLn(X);
  16.   WriteLn('Please provide a value for Y:');
  17.   ReadLn(Y);
  18.  
  19.   WriteLn;
  20.   Write('Analysing the inputs ');
  21.   for i := 1 to 5 do
  22.   begin
  23.     Delay(2000);
  24.     Write('.');
  25.   end;
  26.   WriteLn;
  27.   WriteLn;
  28.  
  29.   XisZero := X = 0;
  30.   YisZero := Y = 0;
  31.   if XisZero                 then WriteLn('The dot is on the Y line.');
  32.   if YisZero                 then WriteLn('The dot is on the X line.');
  33.   if not(XisZero or YisZero) then WriteLn('Nothing special!');
  34.   ReadLn;
  35.  
  36. end.

Note:
Don't copy/paste and submit my code to your teacher. The teacher will know you didn't write the code, also you'll learn nothing.

ilhamrizki25

  • Newbie
  • Posts: 5
Re: HELP CREATE!!
« Reply #5 on: September 07, 2018, 07:50:03 am »
thank you guys for your feedback and help.

And no, I won't just copy paste it.

 

TinyPortal © 2005-2018