Dear Sir,

I have got confused to the real / integer. Would you mind helping to express it to me?

I have got the answer of the following question:

Write a menu system for the currency exchange program. My menu could look like this:

Exchange rates
How much money would you like to exchange?

Press 1 for Australian dollars
2 for US dollars
3 for English pounds
4 for Japanese yen
5 for Euros
6 for Indian rupees
7 for PNG kina
8 for SA rand

My answer:

program Conversion_with_menuII;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  aus=0.9024;
  us=0.7697;
  eng=0.3803;
  y=0.9144;
  e=0.5657;
  rup=31.17;
  kina=1.6197;
  rand=5.1805;

var
  nz_dollar: real;
  aus_out: real;
  us_out: real;
  eng_out: real;
  y_out: real;
  e_out: real;
  rup_out: real;
  kina_out: real;
  rand_out: real;
  choice: integer;

begin
  write('How much money would you lie to change? :$');
  readln(nz_dollar);
  writeln('Please select which currency you would like to convert to');
  writeln('Press 1 for Australian dollars');
  writeln('Press 2 for US dollars');
  writeln('Press 3 for English pounds');
  writeln('Press 4 for Japanese yen');
  writeln('Press 5 for Euros');
  writeln('Press 6 for Indian rupees');
  writeln('Press 7 for PNG kina');
  writeln('Press 8 for SA rand');
  readln(choice);
case choice of
  1: begin
  aus_out:=nz_dollar*aus;
  writeln('The amount in Australian Dollars is: $',aus_out:6:2);
  end;
  2: begin
  us_out:=nz_dollar*us;
  writeln('The amount in US dollars is: $',us_out:6:2);
  end;
  3: begin
  eng_out:=nz_dollar*eng;
  writeln('The amount in English pounds is: $',eng_out:6:2);
  end;
  4: begin
  y_out:=nz_dollar*y;
  writeln('The amount in Japanese yen is: $',y_out:6:2);
  end;
  5: begin
  e_out:=nz_dollar*e;
  writeln('The amount in Euros is: $',e_out:6:2);
  end;
  6: begin
  rup_out:=nz_dollar*rup;
  writeln('The amount in Indian rupees is $',rup_out:6:2);
  end;
  7: begin
  kina_out:=nz_dollar*kina;
  writeln('The amount in PNG kina is $',kina_out:6:2);
  end;
  8: begin
  rand_out:=nz_dollar*rand;
  writeln('The amount in SA rand is $',rand_out:6:2);
  end;
  end;
  readln;
end.

I have tried to change the real to integer but it is work. Could you express the reason to me please?

Cheers,

What do you want convert real to integer?

if only so
writeln('The amount in SA rand is $',rand_out:1:0);
and the result seems like integer number like 12 or 34 without decimal point.....
:D

Int will give you the number before the comma in a real number.

program Convert;

var
r: Real;

begin
r := Int(3.14);
end.

Frac will give you the number after the comma in a real number.

program Convert;

var
r: Real;

begin
r := Frac(3.14);
end.

Round will round off a real number to the nearest integer.

program Convert;

var
i: Integer;

begin
i := Round(3.14);
end.

Trunc will give you the number before the comma of a real number as an integer.

program Convert;

var
i: Integer;

begin
i := Trunc(3.14);
end.

enough? :D

Dear Sir,

Thank you for detailed expression.

Cheers,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.