Našiel som na nete pár programov ale všetko pracuje len s celými číslami. Aj na toto vám viem odpredať, áno viem že niekto si povie ved to vynásob 100 a je to.. Omyl dátový typ real ostal stále real akurát sa stým lepšie pracuje a teda možnosť použiť DIV alebo MOD nieje možné čo sa týka reálnych čísel. Program ako taký s par muchami mám ale bez použitia rekurzie.Zrealizujte rekurzívne aj nerekurzívne riešenie (ak sa dá) programu, ktorý zabezpečí pomocou rekurzívnej procedúry (funkcie) výpis najmenšieho počtu mincí koľko budeme potrebovať na vyplatenie určitej sumy, ak sa v krajine používajú tieto druhy mincí 2€,1€,50cent, 20cent, 10cent, 5cent, 2cent, 1cent.
A tu by som vás chcel poprosiť o pomoc
Kód: Vybrať všetko
program pokladna;
uses crt;
procedure kolkominci(hodnota:real);
var a,b:word;
c,d,e:real;
pom:integer;
poc:real;
cele:word;
desatinne:real;
des:integer;
begin
a:=0;
b:=0;
c:=0;
d:=0;
e:=0;
pom:=0;
poc:=0;
cele:=0;
desatinne:=0;
des:=0;
poc:=hodnota;
cele:=trunc(poc);
writeln('Vhode suma : ',cele);
desatinne:=frac(poc);
writeln('Jej desatinna hodnota : ',desatinne:1:2);
writeln;
writeln;
writeln;
a:=cele;
a:=a div 2;
writeln('Pocet 2EUR minci: ',a);
pom:=cele-(2*a);
b:=pom;
b:=b div 1;
writeln('Pocet 1EUR minci: ',b);
c:=desatinne;
c:=c*100;
c:=c-50;
if c>0 then writeln('Pocet 50Cent minci: 1')
else if c=0 then begin
writeln('Pocet 50Cent minci: 1');
writeln('Pocet 20Cent minci: 0');
writeln('Pocet 10Cent minci: 0');
writeln('Pocet 5Cent minci: 0');
writeln('Pocet 2Cent minci: 0');
writeln('Pocet 1Cent minci: 0');
exit;
end
else writeln('Pocet 50Cent minci: 0');
if c<0 then begin {tento krok je kvoli kladnej hodnote c}
c:=desatinne*100;
d:=c; {tento krok nam vypocita drobne pod 50}
end
else d:=c; {tu sa odpocita -50Cent a ide dalej zo zostatkom}
if d>=40 then begin
writeln('Pocet 20Cent minci: 2');
d:=d-40;
writeln('Pocet 10Cent minci: 0');
end
else if (d<40) and (d>=20) then begin
writeln('Pocet 20Cent minci: 1');
d:=d-20;
if d>=10 then begin writeln('Pocet 10Cent minci: 1');
d:=d-10;
end
else writeln('Pocet 10Cent minci: 0')
end
else begin
writeln('Pocet 20Cent minci: 0');
if d>=10 then begin
writeln ('Pocet 10Cent minci: 1');
d:=d-10; {centi ako 5 2 1}
end
else writeln('Pocet 10Cent minci: 0');
end;
writeln(d:2:1);
if d=9.0 then begin
writeln('Pocet 5Cent minci: 1');
writeln('Pocet 2Cent minci: 2');
end
else
if d=8.0 then begin
writeln('Pocet 5Cent minci: 1');
writeln('Pocet 2Cent minci: 1');
writeln('Pocet 1Cent minci: 1');
end
else
if d=7.0 then begin
writeln('Pocet 5Cent minci: 1');
writeln('Pocet 2Cent minci: 1');
end
else
if d=6.0 then begin
writeln('Pocet 5Cent minci: 1');
writeln('Pocet 1Cent minci: 1')
end
else
if d=5.0 then writeln('Pocet 5Cent minci: 1')
else
if d=4.0 then writeln('Pocet 2Cent minci: 2')
else
if d=3.0 then begin
writeln('Pocet 2Cent minci: 1');
writeln('Pocet 1Cent minci: 1');
end
else
if d=2.0 then writeln('Pocet 2Cent minci: 1')
else
if d=1.0 then writeln('Pocet 1Cent minci: 1')
end;
var suma:real;
begin
clrscr;
writeln('=========================================================');
writeln(' A U T O M A T N A P E N I A Z E ');
writeln;
write('Zadajte penaznu hodnotu = ');
readln(suma);
if suma>0 then begin
kolkominci(suma);
writeln;
write('Vydavam peniaze pockajte prosim');
delay(450);
write('... ');
delay(800);
write(' ..');
delay(1150);
write(' .');
delay(1500);
writeln(' Dovidenia');
end
else writeln('Zadali ste zapornu alebo nulovu hodnotu! Opakujte tento krok');
writeln('=========================================================');
readln;
end.PS : Prepáčte keď som sa netrafil do témy fóra.