Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
please help me with the Roman Calculator homework Posted by cainhk on 16 Apr 2005 at 8:20 AM
Roman number: I,V,X, L, C, D, M
Decimal number: 1,5,10,50,100,500,1000
VI=6
IV=4
sample output is:

First Roman number?XLV
Operator?+
Second Roman number?XVIII
this is 45 plus 18 and answer is LXIII(63).
Report
Re: please help me with the Roman Calculator homework Posted by zibadian on 16 Apr 2005 at 10:02 AM
: Roman number: I,V,X, L, C, D, M
: Decimal number: 1,5,10,50,100,500,1000
: VI=6
: IV=4
: sample output is:
:
: First Roman number?XLV
: Operator?+
: Second Roman number?XVIII
: this is 45 plus 18 and answer is LXIII(63).
:
Step 1: write a roman to decimal converter and a decimal to roman converter
Step 2: write a program, which can calculate the result of a 2 decimals calculation
Step 3: link those together.
Report
Re: please help me with the Roman Calculator homework Posted by Gaashius on 16 Apr 2005 at 12:46 PM
: : Roman number: I,V,X, L, C, D, M
: : Decimal number: 1,5,10,50,100,500,1000
: : VI=6
: : IV=4
: : sample output is:
: :
: : First Roman number?XLV
: : Operator?+
: : Second Roman number?XVIII
: : this is 45 plus 18 and answer is LXIII(63).
: :
: Step 1: write a roman to decimal converter and a decimal to roman converter
: Step 2: write a program, which can calculate the result of a 2 decimals calculation
: Step 3: link those together.
:
Hey Zib this is a bit complicated for our lil friend I think.
Here's a proc for Dec2Rom:
function dec2rom(decimal:word):string;
var
 Ms,Cs,Xs,Is:byte;
 DPrev,LPrev,VPrev:boolean;
 idlint:word;
 br:string;
 n:byte;
begin
 idlint:=decimal; 
 if (idlint<>0) and (idlint>=1000) then begin
  Ms:=idlint div 1000;
  idlint:=idlint mod 1000;
 end;
 if (idlint<>0) and (idlint>=100) then begin
  if idlint>500 then DPrev:=true;
  Cs:=idlint div 100;
  idlint:=idlint mod 100;
  if DPrev then dec(Cs,5);
 end;
 if (idlint<>0) and (idlint>=10) then begin
  if idlint>50 then LPrev:=true;
  Xs:=idlint div 10;
  idlint:=idlint mod 10;
  if LPrev then dec(Xs,5);
 end;
 if (idlint<>0) and (idlint>=1) then begin
  if idlint>5 then VPrev:=true;
  if VPrev then Is:=idlint-5 else Is:=idlint;
 end;
 br:='';
 if Ms>0 then for n:=1 to Ms do br:=br+'M';
 if DPrev then br:=br+'D';
 if Cs>0 then for n:=1 to Cs do br:=br+'C';
 if LPrev then br:=br+'L';
 if Xs>0 then for n:=1 to Xs do br:=br+'X';
 if VPrev then br:=br+'V';
 if Is>0 then for n:=1 to Is do br:=br+'I';
 dec2rom:=br;
end;


OKS? This will be the Rom2Dec(the simplest):
function Rom2Dec(rom:string):word;
var
 br:word;
 n:byte;
begin
 br:=0;
 for n:=1 to length(rom) do begin
  if rom[n]='M' then inc(br,1000);
  if rom[n]='D' then inc(br,500);
  if rom[n]='C' then inc(br,100);
  if rom[n]='V' then inc(br,50);
  if rom[n]='X' then inc(br,10);
  if rom[n]='L' then inc(br,5);
  if rom[n]='I' then inc(br,1);
 end;
end;

I hope it will work and helps you out.

****************
Any questions? Just ask!

GAASHIUS


Report
Re: please help me with the Roman Calculator homework Posted by Gaashius on 16 Apr 2005 at 12:51 PM
: : : Roman number: I,V,X, L, C, D, M
: : : Decimal number: 1,5,10,50,100,500,1000
: : : VI=6
: : : IV=4
: : : sample output is:
: : :
: : : First Roman number?XLV
: : : Operator?+
: : : Second Roman number?XVIII
: : : this is 45 plus 18 and answer is LXIII(63).
: : :
: : Step 1: write a roman to decimal converter and a decimal to roman converter
: : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : Step 3: link those together.
: :
: Hey Zib this is a bit complicated for our lil friend I think.
: Here's a proc for Dec2Rom:
:
: function dec2rom(decimal:word):string;
: var
:  Ms,Cs,Xs,Is:byte;
:  DPrev,LPrev,VPrev:boolean;
:  idlint:word;
:  br:string;
:  n:byte;
: begin
:  idlint:=decimal; 
:  if (idlint<>0) and (idlint>=1000) then begin
:   Ms:=idlint div 1000;
:   idlint:=idlint mod 1000;
:  end;
:  if (idlint<>0) and (idlint>=100) then begin
:   if idlint>500 then DPrev:=true;
:   Cs:=idlint div 100;
:   idlint:=idlint mod 100;
:   if DPrev then dec(Cs,5);
:  end;
:  if (idlint<>0) and (idlint>=10) then begin
:   if idlint>50 then LPrev:=true;
:   Xs:=idlint div 10;
:   idlint:=idlint mod 10;
:   if LPrev then dec(Xs,5);
:  end;
:  if (idlint<>0) and (idlint>=1) then begin
:   if idlint>5 then VPrev:=true;
:   if VPrev then Is:=idlint-5 else Is:=idlint;
:  end;
:  br:='';
:  if Ms>0 then for n:=1 to Ms do br:=br+'M';
:  if DPrev then br:=br+'D';
:  if Cs>0 then for n:=1 to Cs do br:=br+'C';
:  if LPrev then br:=br+'L';
:  if Xs>0 then for n:=1 to Xs do br:=br+'X';
:  if VPrev then br:=br+'V';
:  if Is>0 then for n:=1 to Is do br:=br+'I';
:  dec2rom:=br;
: end;
: 

:
: OKS? This will be the Rom2Dec(the simplest):
:
: function Rom2Dec(rom:string):word;
: var
:  br:word;
:  n:byte;
: begin
:  br:=0;
:  for n:=1 to length(rom) do begin
:   if rom[n]='M' then inc(br,1000);
:   if rom[n]='D' then inc(br,500);
:   if rom[n]='C' then inc(br,100);
:   if rom[n]='V' then inc(br,50);
:   if rom[n]='X' then inc(br,10);
:   if rom[n]='L' then inc(br,5);
:   if rom[n]='I' then inc(br,1);
:  end;
: end;
: 

: I hope it will work and helps you out.
:
: ****************
: Any questions? Just ask!
:
: GAASHIUS
:
:
:
Oh sorry, I have forgotten to write the main body of the program:
uses
 crt;

var
 op:char;
 s1,s2:string;
 res:word;

{ converting routines are here }

begin
 p1:=0;
 p2:=0;
 clrscr;
 write('First Roman Number?'); readln(s1);
 write('Operator?'); readln(op);
 write('Second roman number?'); readln(s2);
 if op='+' then res:=rom2dec(s1)+rom2dec(s2);
 if op='/' then res:=rom2dec(s1) div rom2dec(s2);
 if op='*' then res:=rom2dec(s1)*rom2dec(s2);
 if op='-' then res:=rom2dec(s1)-rom2dec(s2);
 writeln; writeln('Result:'+res);
 readkey;
end.

OKS?

****************
Any questions? Just ask!

GAASHIUS


Report
Re: please help me with the Roman Calculator homework Posted by zibadian on 16 Apr 2005 at 2:06 PM
: : : : Roman number: I,V,X, L, C, D, M
: : : : Decimal number: 1,5,10,50,100,500,1000
: : : : VI=6
: : : : IV=4
: : : : sample output is:
: : : :
: : : : First Roman number?XLV
: : : : Operator?+
: : : : Second Roman number?XVIII
: : : : this is 45 plus 18 and answer is LXIII(63).
: : : :
: : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : Step 3: link those together.
: : :
: : Hey Zib this is a bit complicated for our lil friend I think.
: : Here's a proc for Dec2Rom:
: :
: : function dec2rom(decimal:word):string;
: : var
: :  Ms,Cs,Xs,Is:byte;
: :  DPrev,LPrev,VPrev:boolean;
: :  idlint:word;
: :  br:string;
: :  n:byte;
: : begin
: :  idlint:=decimal; 
: :  if (idlint<>0) and (idlint>=1000) then begin
: :   Ms:=idlint div 1000;
: :   idlint:=idlint mod 1000;
: :  end;
: :  if (idlint<>0) and (idlint>=100) then begin
: :   if idlint>500 then DPrev:=true;
: :   Cs:=idlint div 100;
: :   idlint:=idlint mod 100;
: :   if DPrev then dec(Cs,5);
: :  end;
: :  if (idlint<>0) and (idlint>=10) then begin
: :   if idlint>50 then LPrev:=true;
: :   Xs:=idlint div 10;
: :   idlint:=idlint mod 10;
: :   if LPrev then dec(Xs,5);
: :  end;
: :  if (idlint<>0) and (idlint>=1) then begin
: :   if idlint>5 then VPrev:=true;
: :   if VPrev then Is:=idlint-5 else Is:=idlint;
: :  end;
: :  br:='';
: :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: :  if DPrev then br:=br+'D';
: :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: :  if LPrev then br:=br+'L';
: :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: :  if VPrev then br:=br+'V';
: :  if Is>0 then for n:=1 to Is do br:=br+'I';
: :  dec2rom:=br;
: : end;
: : 

: :
: : OKS? This will be the Rom2Dec(the simplest):
: :
: : function Rom2Dec(rom:string):word;
: : var
: :  br:word;
: :  n:byte;
: : begin
: :  br:=0;
: :  for n:=1 to length(rom) do begin
: :   if rom[n]='M' then inc(br,1000);
: :   if rom[n]='D' then inc(br,500);
: :   if rom[n]='C' then inc(br,100);
: :   if rom[n]='V' then inc(br,50);
: :   if rom[n]='X' then inc(br,10);
: :   if rom[n]='L' then inc(br,5);
: :   if rom[n]='I' then inc(br,1);
: :  end;
: : end;
: : 

: : I hope it will work and helps you out.
: :
: : ****************
: : Any questions? Just ask!
: :
: : GAASHIUS
: :
: :
: :
: Oh sorry, I have forgotten to write the main body of the program:
:
: uses
:  crt;
: 
: var
:  op:char;
:  s1,s2:string;
:  res:word;
: 
: { converting routines are here }
: 
: begin
:  p1:=0;
:  p2:=0;
:  clrscr;
:  write('First Roman Number?'); readln(s1);
:  write('Operator?'); readln(op);
:  write('Second roman number?'); readln(s2);
:  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
:  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
:  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
:  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
:  writeln; writeln('Result:'+res);
:  readkey;
: end.
: 

: OKS?
:
: ****************
: Any questions? Just ask!
:
: GAASHIUS
:
:
:
I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
Report
Re: please help me with the Roman Calculator homework Posted by cainhk on 16 Apr 2005 at 4:10 PM
: : : : : Roman number: I,V,X, L, C, D, M
: : : : : Decimal number: 1,5,10,50,100,500,1000
: : : : : VI=6
: : : : : IV=4
: : : : : sample output is:
: : : : :
: : : : : First Roman number?XLV
: : : : : Operator?+
: : : : : Second Roman number?XVIII
: : : : : this is 45 plus 18 and answer is LXIII(63).
: : : : :
: : : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : : Step 3: link those together.
: : : :
: : : Hey Zib this is a bit complicated for our lil friend I think.
: : : Here's a proc for Dec2Rom:
: : :
: : : function dec2rom(decimal:word):string;
: : : var
: : :  Ms,Cs,Xs,Is:byte;
: : :  DPrev,LPrev,VPrev:boolean;
: : :  idlint:word;
: : :  br:string;
: : :  n:byte;
: : : begin
: : :  idlint:=decimal; 
: : :  if (idlint<>0) and (idlint>=1000) then begin
: : :   Ms:=idlint div 1000;
: : :   idlint:=idlint mod 1000;
: : :  end;
: : :  if (idlint<>0) and (idlint>=100) then begin
: : :   if idlint>500 then DPrev:=true;
: : :   Cs:=idlint div 100;
: : :   idlint:=idlint mod 100;
: : :   if DPrev then dec(Cs,5);
: : :  end;
: : :  if (idlint<>0) and (idlint>=10) then begin
: : :   if idlint>50 then LPrev:=true;
: : :   Xs:=idlint div 10;
: : :   idlint:=idlint mod 10;
: : :   if LPrev then dec(Xs,5);
: : :  end;
: : :  if (idlint<>0) and (idlint>=1) then begin
: : :   if idlint>5 then VPrev:=true;
: : :   if VPrev then Is:=idlint-5 else Is:=idlint;
: : :  end;
: : :  br:='';
: : :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: : :  if DPrev then br:=br+'D';
: : :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: : :  if LPrev then br:=br+'L';
: : :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: : :  if VPrev then br:=br+'V';
: : :  if Is>0 then for n:=1 to Is do br:=br+'I';
: : :  dec2rom:=br;
: : : end;
: : : 

: : :
: : : OKS? This will be the Rom2Dec(the simplest):
: : :
: : : function Rom2Dec(rom:string):word;
: : : var
: : :  br:word;
: : :  n:byte;
: : : begin
: : :  br:=0;
: : :  for n:=1 to length(rom) do begin
: : :   if rom[n]='M' then inc(br,1000);
: : :   if rom[n]='D' then inc(br,500);
: : :   if rom[n]='C' then inc(br,100);
: : :   if rom[n]='V' then inc(br,50);
: : :   if rom[n]='X' then inc(br,10);
: : :   if rom[n]='L' then inc(br,5);
: : :   if rom[n]='I' then inc(br,1);
: : :  end;
: : : end;
: : : 

: : : I hope it will work and helps you out.
: : :
: : : ****************
: : : Any questions? Just ask!
: : :
: : : GAASHIUS
: : :
: : :
: : :
: : Oh sorry, I have forgotten to write the main body of the program:
: :
: : uses
: :  crt;
: : 
: : var
: :  op:char;
: :  s1,s2:string;
: :  res:word;
: : 
: : { converting routines are here }
: : 
: : begin
: :  p1:=0;
: :  p2:=0;
: :  clrscr;
: :  write('First Roman Number?'); readln(s1);
: :  write('Operator?'); readln(op);
: :  write('Second roman number?'); readln(s2);
: :  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
: :  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
: :  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
: :  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
: :  writeln; writeln('Result:'+res);
: :  readkey;
: : end.
: : 

: : OKS?
: :
: : ****************
: : Any questions? Just ask!
: :
: : GAASHIUS
: :
: :
: :
: I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
:
:thank you gaa,zib too
Report
Re: please help me with the Roman Calculator homework Posted by cainhk on 16 Apr 2005 at 4:27 PM
: : : : : : Roman number: I,V,X, L, C, D, M
: : : : : : Decimal number: 1,5,10,50,100,500,1000
: : : : : : VI=6
: : : : : : IV=4
: : : : : : sample output is:
: : : : : :
: : : : : : First Roman number?XLV
: : : : : : Operator?+
: : : : : : Second Roman number?XVIII
: : : : : : this is 45 plus 18 and answer is LXIII(63).
: : : : : :
: : : : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : : : Step 3: link those together.
: : : : :
: : : : Hey Zib this is a bit complicated for our lil friend I think.
: : : : Here's a proc for Dec2Rom:
: : : :
: : : : function dec2rom(decimal:word):string;
: : : : var
: : : :  Ms,Cs,Xs,Is:byte;
: : : :  DPrev,LPrev,VPrev:boolean;
: : : :  idlint:word;
: : : :  br:string;
: : : :  n:byte;
: : : : begin
: : : :  idlint:=decimal; 
: : : :  if (idlint<>0) and (idlint>=1000) then begin
: : : :   Ms:=idlint div 1000;
: : : :   idlint:=idlint mod 1000;
: : : :  end;
: : : :  if (idlint<>0) and (idlint>=100) then begin
: : : :   if idlint>500 then DPrev:=true;
: : : :   Cs:=idlint div 100;
: : : :   idlint:=idlint mod 100;
: : : :   if DPrev then dec(Cs,5);
: : : :  end;
: : : :  if (idlint<>0) and (idlint>=10) then begin
: : : :   if idlint>50 then LPrev:=true;
: : : :   Xs:=idlint div 10;
: : : :   idlint:=idlint mod 10;
: : : :   if LPrev then dec(Xs,5);
: : : :  end;
: : : :  if (idlint<>0) and (idlint>=1) then begin
: : : :   if idlint>5 then VPrev:=true;
: : : :   if VPrev then Is:=idlint-5 else Is:=idlint;
: : : :  end;
: : : :  br:='';
: : : :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: : : :  if DPrev then br:=br+'D';
: : : :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: : : :  if LPrev then br:=br+'L';
: : : :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: : : :  if VPrev then br:=br+'V';
: : : :  if Is>0 then for n:=1 to Is do br:=br+'I';
: : : :  dec2rom:=br;
: : : : end;
: : : : 

: : : :
: : : : OKS? This will be the Rom2Dec(the simplest):
: : : :
: : : : function Rom2Dec(rom:string):word;
: : : : var
: : : :  br:word;
: : : :  n:byte;
: : : : begin
: : : :  br:=0;
: : : :  for n:=1 to length(rom) do begin
: : : :   if rom[n]='M' then inc(br,1000);
: : : :   if rom[n]='D' then inc(br,500);
: : : :   if rom[n]='C' then inc(br,100);
: : : :   if rom[n]='V' then inc(br,50);
: : : :   if rom[n]='X' then inc(br,10);
: : : :   if rom[n]='L' then inc(br,5);
: : : :   if rom[n]='I' then inc(br,1);
: : : :  end;
: : : : end;
: : : : 

: : : : I hope it will work and helps you out.
: : : :
: : : : ****************
: : : : Any questions? Just ask!
: : : :
: : : : GAASHIUS
: : : :
: : : :
: : : :
: : : Oh sorry, I have forgotten to write the main body of the program:
: : :
: : : uses
: : :  crt;
: : : 
: : : var
: : :  op:char;
: : :  s1,s2:string;
: : :  res:word;
: : : 
: : : { converting routines are here }
: : : 
: : : begin
: : :  p1:=0;
: : :  p2:=0;
: : :  clrscr;
: : :  write('First Roman Number?'); readln(s1);
: : :  write('Operator?'); readln(op);
: : :  write('Second roman number?'); readln(s2);
: : :  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
: : :  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
: : :  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
: : :  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
: : :  writeln; writeln('Result:'+res);
: : :  readkey;
: : : end.
: : : 

: : : OKS?
: : :
: : : ****************
: : : Any questions? Just ask!
: : :
: : : GAASHIUS
: : :
: : :
: : :
: : I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
: :
: :thank you gaa,zib too. But how about 'if the input numbers or the result are out of range(greater than or equal to 4000)should display error message '?
:

Report
Re: please help me with the Roman Calculator homework Posted by cainhk on 16 Apr 2005 at 4:45 PM
: : : : : : : Roman number: I,V,X, L, C, D, M
: : : : : : : Decimal number: 1,5,10,50,100,500,1000
: : : : : : : VI=6
: : : : : : : IV=4
: : : : : : : sample output is:
: : : : : : :
: : : : : : : First Roman number?XLV
: : : : : : : Operator?+
: : : : : : : Second Roman number?XVIII
: : : : : : : this is 45 plus 18 and answer is LXIII(63).
: : : : : : :
: : : : : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : : : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : : : : Step 3: link those together.
: : : : : :
: : : : : Hey Zib this is a bit complicated for our lil friend I think.
: : : : : Here's a proc for Dec2Rom:
: : : : :
: : : : : function dec2rom(decimal:word):string;
: : : : : var
: : : : :  Ms,Cs,Xs,Is:byte;
: : : : :  DPrev,LPrev,VPrev:boolean;
: : : : :  idlint:word;
: : : : :  br:string;
: : : : :  n:byte;
: : : : : begin
: : : : :  idlint:=decimal; 
: : : : :  if (idlint<>0) and (idlint>=1000) then begin
: : : : :   Ms:=idlint div 1000;
: : : : :   idlint:=idlint mod 1000;
: : : : :  end;
: : : : :  if (idlint<>0) and (idlint>=100) then begin
: : : : :   if idlint>500 then DPrev:=true;
: : : : :   Cs:=idlint div 100;
: : : : :   idlint:=idlint mod 100;
: : : : :   if DPrev then dec(Cs,5);
: : : : :  end;
: : : : :  if (idlint<>0) and (idlint>=10) then begin
: : : : :   if idlint>50 then LPrev:=true;
: : : : :   Xs:=idlint div 10;
: : : : :   idlint:=idlint mod 10;
: : : : :   if LPrev then dec(Xs,5);
: : : : :  end;
: : : : :  if (idlint<>0) and (idlint>=1) then begin
: : : : :   if idlint>5 then VPrev:=true;
: : : : :   if VPrev then Is:=idlint-5 else Is:=idlint;
: : : : :  end;
: : : : :  br:='';
: : : : :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: : : : :  if DPrev then br:=br+'D';
: : : : :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: : : : :  if LPrev then br:=br+'L';
: : : : :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: : : : :  if VPrev then br:=br+'V';
: : : : :  if Is>0 then for n:=1 to Is do br:=br+'I';
: : : : :  dec2rom:=br;
: : : : : end;
: : : : : 

: : : : :
: : : : : OKS? This will be the Rom2Dec(the simplest):
: : : : :
: : : : : function Rom2Dec(rom:string):word;
: : : : : var
: : : : :  br:word;
: : : : :  n:byte;
: : : : : begin
: : : : :  br:=0;
: : : : :  for n:=1 to length(rom) do begin
: : : : :   if rom[n]='M' then inc(br,1000);
: : : : :   if rom[n]='D' then inc(br,500);
: : : : :   if rom[n]='C' then inc(br,100);
: : : : :   if rom[n]='V' then inc(br,50);
: : : : :   if rom[n]='X' then inc(br,10);
: : : : :   if rom[n]='L' then inc(br,5);
: : : : :   if rom[n]='I' then inc(br,1);
: : : : :  end;
: : : : : end;
: : : : : 

: : : : : I hope it will work and helps you out.
: : : : :
: : : : : ****************
: : : : : Any questions? Just ask!
: : : : :
: : : : : GAASHIUS
: : : : :
: : : : :
: : : : :
: : : : Oh sorry, I have forgotten to write the main body of the program:
: : : :
: : : : uses
: : : :  crt;
: : : : 
: : : : var
: : : :  op:char;
: : : :  s1,s2:string;
: : : :  res:word;
: : : : 
: : : : { converting routines are here }
: : : : 
: : : : begin
: : : :  p1:=0;
: : : :  p2:=0;
: : : :  clrscr;
: : : :  write('First Roman Number?'); readln(s1);
: : : :  write('Operator?'); readln(op);
: : : :  write('Second roman number?'); readln(s2);
: : : :  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
: : : :  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
: : : :  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
: : : :  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
: : : :  writeln; writeln('Result:'+res);
: : : :  readkey;
: : : : end.
: : : : 

: : : : OKS?
: : : :
: : : : ****************
: : : : Any questions? Just ask!
: : : :
: : : : GAASHIUS
: : : :
: : : :
: : : :
: : : I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
: : :
: : :thank you gaa,zib too. But how about 'if the input numbers or the result are out of range(greater than or equal to 4000)should display error message '?
: :
: THE ROMAN TO DECIMAL PART IS NOT WROK
:

Report
Re: please help me with the Roman Calculator homework Posted by cainhk on 16 Apr 2005 at 5:19 PM
: : : : : : : : Roman number: I,V,X, L, C, D, M
: : : : : : : : Decimal number: 1,5,10,50,100,500,1000
: : : : : : : : VI=6
: : : : : : : : IV=4
: : : : : : : : sample output is:
: : : : : : : :
: : : : : : : : First Roman number?XLV
: : : : : : : : Operator?+
: : : : : : : : Second Roman number?XVIII
: : : : : : : : this is 45 plus 18 and answer is LXIII(63).
: : : : : : : :
: : : : : : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : : : : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : : : : : Step 3: link those together.
: : : : : : :
: : : : : : Hey Zib this is a bit complicated for our lil friend I think.
: : : : : : Here's a proc for Dec2Rom:
: : : : : :
: : : : : : function dec2rom(decimal:word):string;
: : : : : : var
: : : : : :  Ms,Cs,Xs,Is:byte;
: : : : : :  DPrev,LPrev,VPrev:boolean;
: : : : : :  idlint:word;
: : : : : :  br:string;
: : : : : :  n:byte;
: : : : : : begin
: : : : : :  idlint:=decimal; 
: : : : : :  if (idlint<>0) and (idlint>=1000) then begin
: : : : : :   Ms:=idlint div 1000;
: : : : : :   idlint:=idlint mod 1000;
: : : : : :  end;
: : : : : :  if (idlint<>0) and (idlint>=100) then begin
: : : : : :   if idlint>500 then DPrev:=true;
: : : : : :   Cs:=idlint div 100;
: : : : : :   idlint:=idlint mod 100;
: : : : : :   if DPrev then dec(Cs,5);
: : : : : :  end;
: : : : : :  if (idlint<>0) and (idlint>=10) then begin
: : : : : :   if idlint>50 then LPrev:=true;
: : : : : :   Xs:=idlint div 10;
: : : : : :   idlint:=idlint mod 10;
: : : : : :   if LPrev then dec(Xs,5);
: : : : : :  end;
: : : : : :  if (idlint<>0) and (idlint>=1) then begin
: : : : : :   if idlint>5 then VPrev:=true;
: : : : : :   if VPrev then Is:=idlint-5 else Is:=idlint;
: : : : : :  end;
: : : : : :  br:='';
: : : : : :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: : : : : :  if DPrev then br:=br+'D';
: : : : : :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: : : : : :  if LPrev then br:=br+'L';
: : : : : :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: : : : : :  if VPrev then br:=br+'V';
: : : : : :  if Is>0 then for n:=1 to Is do br:=br+'I';
: : : : : :  dec2rom:=br;
: : : : : : end;
: : : : : : 

: : : : : :
: : : : : : OKS? This will be the Rom2Dec(the simplest):
: : : : : :
: : : : : : function Rom2Dec(rom:string):word;
: : : : : : var
: : : : : :  br:word;
: : : : : :  n:byte;
: : : : : : begin
: : : : : :  br:=0;
: : : : : :  for n:=1 to length(rom) do begin
: : : : : :   if rom[n]='M' then inc(br,1000);
: : : : : :   if rom[n]='D' then inc(br,500);
: : : : : :   if rom[n]='C' then inc(br,100);
: : : : : :   if rom[n]='V' then inc(br,50);
: : : : : :   if rom[n]='X' then inc(br,10);
: : : : : :   if rom[n]='L' then inc(br,5);
: : : : : :   if rom[n]='I' then inc(br,1);
: : : : : :  end;
: : : : : : end;
: : : : : : 

: : : : : : I hope it will work and helps you out.
: : : : : :
: : : : : : ****************
: : : : : : Any questions? Just ask!
: : : : : :
: : : : : : GAASHIUS
: : : : : :
: : : : : :
: : : : : :
: : : : : Oh sorry, I have forgotten to write the main body of the program:
: : : : :
: : : : : uses
: : : : :  crt;
: : : : : 
: : : : : var
: : : : :  op:char;
: : : : :  s1,s2:string;
: : : : :  res:word;
: : : : : 
: : : : : { converting routines are here }
: : : : : 
: : : : : begin
: : : : :  p1:=0;
: : : : :  p2:=0;
: : : : :  clrscr;
: : : : :  write('First Roman Number?'); readln(s1);
: : : : :  write('Operator?'); readln(op);
: : : : :  write('Second roman number?'); readln(s2);
: : : : :  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
: : : : :  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
: : : : :  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
: : : : :  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
: : : : :  writeln; writeln('Result:'+res);
: : : : :  readkey;
: : : : : end.
: : : : : 

: : : : : OKS?
: : : : :
: : : : : ****************
: : : : : Any questions? Just ask!
: : : : :
: : : : : GAASHIUS
: : : : :
: : : : :
: : : : :
: : : : I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
: : : :
: : : :thank you gaa,zib too. But how about 'if the input numbers or the result are out of range(greater than or equal to 4000)should display error message '?
: : :
: : THE ROMAN TO DECIMAL PART IS NOT WROK
: :
I'M SORRY, BUT THE HOLE PROGRAMME IS WRONG,OR YOU CAN TRY YOUSELVES
THE DECIMAL TO WORD IS WRONG ;
JUST THINK FOR YOUR SHARING
:
:

Report
Re: please help me with the Roman Calculator homework Posted by cainhk on 16 Apr 2005 at 5:19 PM
: : : : : : : : : Roman number: I,V,X, L, C, D, M
: : : : : : : : : Decimal number: 1,5,10,50,100,500,1000
: : : : : : : : : VI=6
: : : : : : : : : IV=4
: : : : : : : : : sample output is:
: : : : : : : : :
: : : : : : : : : First Roman number?XLV
: : : : : : : : : Operator?+
: : : : : : : : : Second Roman number?XVIII
: : : : : : : : : this is 45 plus 18 and answer is LXIII(63).
: : : : : : : : :
: : : : : : : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : : : : : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : : : : : : Step 3: link those together.
: : : : : : : :
: : : : : : : Hey Zib this is a bit complicated for our lil friend I think.
: : : : : : : Here's a proc for Dec2Rom:
: : : : : : :
: : : : : : : function dec2rom(decimal:word):string;
: : : : : : : var
: : : : : : :  Ms,Cs,Xs,Is:byte;
: : : : : : :  DPrev,LPrev,VPrev:boolean;
: : : : : : :  idlint:word;
: : : : : : :  br:string;
: : : : : : :  n:byte;
: : : : : : : begin
: : : : : : :  idlint:=decimal; 
: : : : : : :  if (idlint<>0) and (idlint>=1000) then begin
: : : : : : :   Ms:=idlint div 1000;
: : : : : : :   idlint:=idlint mod 1000;
: : : : : : :  end;
: : : : : : :  if (idlint<>0) and (idlint>=100) then begin
: : : : : : :   if idlint>500 then DPrev:=true;
: : : : : : :   Cs:=idlint div 100;
: : : : : : :   idlint:=idlint mod 100;
: : : : : : :   if DPrev then dec(Cs,5);
: : : : : : :  end;
: : : : : : :  if (idlint<>0) and (idlint>=10) then begin
: : : : : : :   if idlint>50 then LPrev:=true;
: : : : : : :   Xs:=idlint div 10;
: : : : : : :   idlint:=idlint mod 10;
: : : : : : :   if LPrev then dec(Xs,5);
: : : : : : :  end;
: : : : : : :  if (idlint<>0) and (idlint>=1) then begin
: : : : : : :   if idlint>5 then VPrev:=true;
: : : : : : :   if VPrev then Is:=idlint-5 else Is:=idlint;
: : : : : : :  end;
: : : : : : :  br:='';
: : : : : : :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: : : : : : :  if DPrev then br:=br+'D';
: : : : : : :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: : : : : : :  if LPrev then br:=br+'L';
: : : : : : :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: : : : : : :  if VPrev then br:=br+'V';
: : : : : : :  if Is>0 then for n:=1 to Is do br:=br+'I';
: : : : : : :  dec2rom:=br;
: : : : : : : end;
: : : : : : : 

: : : : : : :
: : : : : : : OKS? This will be the Rom2Dec(the simplest):
: : : : : : :
: : : : : : : function Rom2Dec(rom:string):word;
: : : : : : : var
: : : : : : :  br:word;
: : : : : : :  n:byte;
: : : : : : : begin
: : : : : : :  br:=0;
: : : : : : :  for n:=1 to length(rom) do begin
: : : : : : :   if rom[n]='M' then inc(br,1000);
: : : : : : :   if rom[n]='D' then inc(br,500);
: : : : : : :   if rom[n]='C' then inc(br,100);
: : : : : : :   if rom[n]='V' then inc(br,50);
: : : : : : :   if rom[n]='X' then inc(br,10);
: : : : : : :   if rom[n]='L' then inc(br,5);
: : : : : : :   if rom[n]='I' then inc(br,1);
: : : : : : :  end;
: : : : : : : end;
: : : : : : : 

: : : : : : : I hope it will work and helps you out.
: : : : : : :
: : : : : : : ****************
: : : : : : : Any questions? Just ask!
: : : : : : :
: : : : : : : GAASHIUS
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : Oh sorry, I have forgotten to write the main body of the program:
: : : : : :
: : : : : : uses
: : : : : :  crt;
: : : : : : 
: : : : : : var
: : : : : :  op:char;
: : : : : :  s1,s2:string;
: : : : : :  res:word;
: : : : : : 
: : : : : : { converting routines are here }
: : : : : : 
: : : : : : begin
: : : : : :  p1:=0;
: : : : : :  p2:=0;
: : : : : :  clrscr;
: : : : : :  write('First Roman Number?'); readln(s1);
: : : : : :  write('Operator?'); readln(op);
: : : : : :  write('Second roman number?'); readln(s2);
: : : : : :  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
: : : : : :  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
: : : : : :  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
: : : : : :  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
: : : : : :  writeln; writeln('Result:'+res);
: : : : : :  readkey;
: : : : : : end.
: : : : : : 

: : : : : : OKS?
: : : : : :
: : : : : : ****************
: : : : : : Any questions? Just ask!
: : : : : :
: : : : : : GAASHIUS
: : : : : :
: : : : : :
: : : : : :
: : : : : I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
: : : : :
: : : : :thank you gaa,zib too. But how about 'if the input numbers or the result are out of range(greater than or equal to 4000)should display error message '?
: : : :
: : : THE ROMAN TO DECIMAL PART IS NOT WROK
: : :
: I'M SORRY, BUT THE HOLE PROGRAMME IS WRONG,OR YOU CAN TRY YOUSELVES
: THE DECIMAL TO WORD IS WRONG ;
: JUST THANK FOR YOUR SHARING
: :
: :
:
:

Report
Re: please help me with the Roman Calculator homework Posted by Gaashius on 3 May 2005 at 12:28 AM
: : : : : : : : : : Roman number: I,V,X, L, C, D, M
: : : : : : : : : : Decimal number: 1,5,10,50,100,500,1000
: : : : : : : : : : VI=6
: : : : : : : : : : IV=4
: : : : : : : : : : sample output is:
: : : : : : : : : :
: : : : : : : : : : First Roman number?XLV
: : : : : : : : : : Operator?+
: : : : : : : : : : Second Roman number?XVIII
: : : : : : : : : : this is 45 plus 18 and answer is LXIII(63).
: : : : : : : : : :
: : : : : : : : : Step 1: write a roman to decimal converter and a decimal to roman converter
: : : : : : : : : Step 2: write a program, which can calculate the result of a 2 decimals calculation
: : : : : : : : : Step 3: link those together.
: : : : : : : : :
: : : : : : : : Hey Zib this is a bit complicated for our lil friend I think.
: : : : : : : : Here's a proc for Dec2Rom:
: : : : : : : :
: : : : : : : : function dec2rom(decimal:word):string;
: : : : : : : : var
: : : : : : : :  Ms,Cs,Xs,Is:byte;
: : : : : : : :  DPrev,LPrev,VPrev:boolean;
: : : : : : : :  idlint:word;
: : : : : : : :  br:string;
: : : : : : : :  n:byte;
: : : : : : : : begin
: : : : : : : :  idlint:=decimal; 
: : : : : : : :  if (idlint<>0) and (idlint>=1000) then begin
: : : : : : : :   Ms:=idlint div 1000;
: : : : : : : :   idlint:=idlint mod 1000;
: : : : : : : :  end;
: : : : : : : :  if (idlint<>0) and (idlint>=100) then begin
: : : : : : : :   if idlint>500 then DPrev:=true;
: : : : : : : :   Cs:=idlint div 100;
: : : : : : : :   idlint:=idlint mod 100;
: : : : : : : :   if DPrev then dec(Cs,5);
: : : : : : : :  end;
: : : : : : : :  if (idlint<>0) and (idlint>=10) then begin
: : : : : : : :   if idlint>50 then LPrev:=true;
: : : : : : : :   Xs:=idlint div 10;
: : : : : : : :   idlint:=idlint mod 10;
: : : : : : : :   if LPrev then dec(Xs,5);
: : : : : : : :  end;
: : : : : : : :  if (idlint<>0) and (idlint>=1) then begin
: : : : : : : :   if idlint>5 then VPrev:=true;
: : : : : : : :   if VPrev then Is:=idlint-5 else Is:=idlint;
: : : : : : : :  end;
: : : : : : : :  br:='';
: : : : : : : :  if Ms>0 then for n:=1 to Ms do br:=br+'M';
: : : : : : : :  if DPrev then br:=br+'D';
: : : : : : : :  if Cs>0 then for n:=1 to Cs do br:=br+'C';
: : : : : : : :  if LPrev then br:=br+'L';
: : : : : : : :  if Xs>0 then for n:=1 to Xs do br:=br+'X';
: : : : : : : :  if VPrev then br:=br+'V';
: : : : : : : :  if Is>0 then for n:=1 to Is do br:=br+'I';
: : : : : : : :  dec2rom:=br;
: : : : : : : : end;
: : : : : : : : 

: : : : : : : :
: : : : : : : : OKS? This will be the Rom2Dec(the simplest):
: : : : : : : :
: : : : : : : : function Rom2Dec(rom:string):word;
: : : : : : : : var
: : : : : : : :  br:word;
: : : : : : : :  n:byte;
: : : : : : : : begin
: : : : : : : :  br:=0;
: : : : : : : :  for n:=1 to length(rom) do begin
: : : : : : : :   if rom[n]='M' then inc(br,1000);
: : : : : : : :   if rom[n]='D' then inc(br,500);
: : : : : : : :   if rom[n]='C' then inc(br,100);
: : : : : : : :   if rom[n]='V' then inc(br,50);
: : : : : : : :   if rom[n]='X' then inc(br,10);
: : : : : : : :   if rom[n]='L' then inc(br,5);
: : : : : : : :   if rom[n]='I' then inc(br,1);
: : : : : : : :  end;
: : : : : : : : end;
: : : : : : : : 

: : : : : : : : I hope it will work and helps you out.
: : : : : : : :
: : : : : : : : ****************
: : : : : : : : Any questions? Just ask!
: : : : : : : :
: : : : : : : : GAASHIUS
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : Oh sorry, I have forgotten to write the main body of the program:
: : : : : : :
: : : : : : : uses
: : : : : : :  crt;
: : : : : : : 
: : : : : : : var
: : : : : : :  op:char;
: : : : : : :  s1,s2:string;
: : : : : : :  res:word;
: : : : : : : 
: : : : : : : { converting routines are here }
: : : : : : : 
: : : : : : : begin
: : : : : : :  p1:=0;
: : : : : : :  p2:=0;
: : : : : : :  clrscr;
: : : : : : :  write('First Roman Number?'); readln(s1);
: : : : : : :  write('Operator?'); readln(op);
: : : : : : :  write('Second roman number?'); readln(s2);
: : : : : : :  if op='+' then res:=rom2dec(s1)+rom2dec(s2);
: : : : : : :  if op='/' then res:=rom2dec(s1) div rom2dec(s2);
: : : : : : :  if op='*' then res:=rom2dec(s1)*rom2dec(s2);
: : : : : : :  if op='-' then res:=rom2dec(s1)-rom2dec(s2);
: : : : : : :  writeln; writeln('Result:'+res);
: : : : : : :  readkey;
: : : : : : : end.
: : : : : : : 

: : : : : : : OKS?
: : : : : : :
: : : : : : : ****************
: : : : : : : Any questions? Just ask!
: : : : : : :
: : : : : : : GAASHIUS
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : I never make people's homework, because then they'll never learn to program. Programming is something you learn by doing it, and not from reading about it.
: : : : : :
: : : : : :thank you gaa,zib too. But how about 'if the input numbers or the result are out of range(greater than or equal to 4000)should display error message '?
: : : : :
: : : : THE ROMAN TO DECIMAL PART IS NOT WROK
: : : :
: : I'M SORRY, BUT THE HOLE PROGRAMME IS WRONG,OR YOU CAN TRY YOUSELVES
: : THE DECIMAL TO WORD IS WRONG ;
: : JUST THANK FOR YOUR SHARING
: : :
: : :
: :
: :
:
:
Well sorry for this LATE reply - it would stir the messages - but I have to fix my silly things. Who want to use these converting procs need to put these lines after BEGIN.
...
begin
 Ms:=0;
 Xs:=0;
 Is:=0;
 Cs:=0;
 Dprev:=false;
 Lprev:=false;
 Vprev:=false;
 idlint:=decimal;
...

This will fix the problem - and sorry again.

****************
Any questions? Just ask!

GAASHIUS





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.