MAPA DE TROCO
Moderador: Moderadores
-
informais
- Usuário Nível 1

- Mensagens: 23
- Registrado em: 15 Jun 2018 07:14
- Localização: VISCONDE DO RIO BRANCO
MAPA DE TROCO
Olá amigos, bom dia
Preciso fazer um Mapa de troco,
Exemplo
R$ 45,30
2 Nota(s) de R$ 20,00
4 Nota(s) de R$ 10,00
1 Nota(s) de R$ 5,00
3 Moedas de R$ 0,10
etc
Algo mais ou menos assim
Preciso fazer um Mapa de troco,
Exemplo
R$ 45,30
2 Nota(s) de R$ 20,00
4 Nota(s) de R$ 10,00
1 Nota(s) de R$ 5,00
3 Moedas de R$ 0,10
etc
Algo mais ou menos assim
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
também poderia ser 1 moeda de 0.25 e 1 de 0,05informais escreveu:R$ 45,30
2 Nota(s) de R$ 20,00
4 Nota(s) de R$ 10,00
1 Nota(s) de R$ 5,00
3 Moedas de R$ 0,10
Ou 3 reais de troco, poderiam ser 3 moedas de 1, ou 1 nota de 2 + 1 moeda de 1
É fazer a tabela de notas/moedas.
Vai usar Int() e Mod().
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
Código: Selecionar todos
PROCEDURE Main
LOCAL nValor := 45.30
LOCAL aItem
FOR EACH aItem IN Troco( nValor )
? Str( aItem[ 1 ], 3 ) + " " + aItem[ 2 ] + " de " + Str( aItem[ 3 ] )
NEXT
Inkey(0)
RETURN
FUNCTION Troco( nValor )
LOCAL aList := { ;
{ 50, "nota(s)" }, ;
{ 20, "nota(s)" }, ;
{ 10, "nota(s)" }, ;
{ 5, "nota(s)" }, ;
{ 2, "nota(s)" }, ;
{ 1, "moeda(s)" }, ;
{ 0.50, "moeda(s)" }, ;
{ 0.25, "moeda(s)" }, ;
{ 0.10, "moeda(s)" }, ;
{ 0.05, "moeda(s)" }, ;
{ 0.01, "moeda(s)" } }
LOCAL aTroco := {}
LOCAL aItem, nQtd
FOR EACH aItem IN aList
nQtd := Int( nValor / aItem[ 1 ] )
? nValor, aItem[ 1 ], nQtd
IF nValor >= aItem[ 1 ]
nValor := nValor - ( nQtd * aItem[ 1 ] )
AAdd( aTroco, { nQtd, aItem[ 2 ], aItem[ 1 ] } )
ENDIF
NEXT
RETURN aTroco
0.05 / 0.05 deu zero
e 0.05 / 0.01 deu 4
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
Código: Selecionar todos
PROCEDURE Main
LOCAL nValor := 45.30
LOCAL nItem
FOR EACH nItem IN Troco( nValor )
? Str( nItem[ 1 ], 2 ) + " " + iif( nItem[ 1 ] < 2, "moeda(s)", "nota(s)" ) + " de " + Str( nItem[ 2 ] )
NEXT
Inkey(0)
RETURN
FUNCTION Troco( nValor )
LOCAL aList := { 50, 20, 10, 5, 2, 1, 0.50, 0.25, 0.10, 0.05, 0.01 }
LOCAL aTroco := {}
LOCAL nItem, nQtd
nValor := Int( nValor * 100 )
FOR EACH nItem IN aList
nQtd := Int( nValor / ( nItem * 100 ) )
//? nValor/100, nItem, nQtd
IF nValor >= ( nItem * 100 )
nValor := nValor - ( nQtd * nItem * 100 )
AAdd( aTroco, { nQtd, nItem } )
ENDIF
NEXT
RETURN aTroco
E trabalhando com valor multiplicado por 100, pra evitar erro de cálculo.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
Aproveitando...
Pra quem nunca viu erro de cálculo por causa do tal ponto flutuante, está aí.
Internamente 0.05 virou algo como 0.049999999999999999999999999999
Numa visão normal, tudo bem, mas em cálculos detalhados.... erro de cálculo.
Pra quem nunca viu erro de cálculo por causa do tal ponto flutuante, está aí.
Internamente 0.05 virou algo como 0.049999999999999999999999999999
Numa visão normal, tudo bem, mas em cálculos detalhados.... erro de cálculo.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
Pequena correção no fonte:
Ao invés de comparar o valor, eu tinha comparado a quantidade.
Código: Selecionar todos
iif( nItem[ 2 ] < 2, "moeda(s)", "nota(s)" )
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
-
Fernando queiroz
- Usuário Nível 4

- Mensagens: 779
- Registrado em: 13 Nov 2014 00:41
- Localização: Porto Alegre/RS
MAPA DE TROCO
O único problema é saber o tipo e a quantidade do troco, ou tal mapa é somente para informacao?????
caso não seja somente para informação tem de carregar os tipos de notas e moedas, como acontece em caixa eletrônico, que você informa a quantidade de notas, valor e qual cassete ela esta localizada.
no caso de caixa eletronico tem somente dispenser e o recebimento é separado.
Quando trabalhei em Banco , dava manutenção em sistema de caixa eletrônico, era bem legal, tratar o hardware para contar e recusar notas com defeito
caso não seja somente para informação tem de carregar os tipos de notas e moedas, como acontece em caixa eletrônico, que você informa a quantidade de notas, valor e qual cassete ela esta localizada.
no caso de caixa eletronico tem somente dispenser e o recebimento é separado.
Quando trabalhei em Banco , dava manutenção em sistema de caixa eletrônico, era bem legal, tratar o hardware para contar e recusar notas com defeito
HARBOUR 3.2, HWGUI 2.23 B3, SEFAZCLASS, PDFClass, ADO + MariaDB/MySQL, RMChart
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
Não prestei atenção sobre o tópico ser Clipper.
Troque o FOR/EACH por FOR nCont = 1 TO n, e acrescente uma linha.
troque por
E ao invés de usar direto o Troco( nValor ) no FOR/EACH, primeiro atribua a uma variável.
troque por
Assim o resto do fonte permanece igual.
Troque o FOR/EACH por FOR nCont = 1 TO n, e acrescente uma linha.
Código: Selecionar todos
FOR EACH nItem IN a List
Código: Selecionar todos
FOR nCont = 1 TO Len( aList )
aItem := aList[ nCont ]
Código: Selecionar todos
FOR EACH nItem IN Troco( nValor )
Código: Selecionar todos
aList := Troco( nValor )
FOR nCont = 1 TO Len( aList )
nItem := aList[ nCont ]
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MAPA DE TROCO
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/