Formule mal exprimée

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
ThoT
Messages : 33
Inscription : mar. 20/mars/2007 17:51

Formule mal exprimée

Message par ThoT »

Je souhaite créer un petit programme qui calcule les mensualités d'un emprunt en fonction du montant de l'emprunt, du taux d'interet et de la durée de remboursement.
Le souci est que je n'obtiens pas les resultats voulus.

Pour la formule, je l'ai prise sur ce site : http://easycompte.free.fr/Scripts/Emprunt_com.php

Voilà mon code qui me pose probléme :

Code : Tout sélectionner

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Text_0
  #Text_1
  #Text_2
  #String_0
  #String_1
  #String_2
  #Text_3
  #Text_4
  #Frame3D_0
  #Frame3D_1
  #String_4
  #String_5
  #Text_6
EndEnumeration


Global FontID1
FontID1 = LoadFont(1, "Arial", 26, #PB_Font_Bold)


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 430, 280, "Logibanque",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      TextGadget(#Text_0, -10, 85, 200, 20, "Somme empruntée", #PB_Text_Right)
      TextGadget(#Text_1, -10, 115, 200, 20, "Taux d'interet (en %)", #PB_Text_Right)
      TextGadget(#Text_2, -10, 145, 200, 20, "Durée de l'emprunt (en années)", #PB_Text_Right)
      StringGadget(#String_0, 200, 80, 200, 20, "0")
      StringGadget(#String_1, 200, 110, 200, 20, "0")
      StringGadget(#String_2, 200, 140, 200, 20, "0")
      TextGadget(#Text_3, -10, 205, 200, 20, "Remboursement mensuel", #PB_Text_Right)
      TextGadget(#Text_4, -10, 235, 200, 20, "Coût de l'emprunt", #PB_Text_Right)
      Frame3DGadget(#Frame3D_0, 20, 65, 390, 110, "Paramétres d'emprunt")
      Frame3DGadget(#Frame3D_1, 20, 185, 390, 80, "Valeurs calculées")
      StringGadget(#String_4, 200, 200, 200, 20, "0", #PB_String_ReadOnly)
      StringGadget(#String_5, 200, 230, 200, 20, "0", #PB_String_ReadOnly)
      TextGadget(#Text_6, 80, 10, 250, 50, "Logibanque", #PB_Text_Center)
      SetGadgetFont(#Text_6, FontID1)
      
    EndIf
  EndIf
EndProcedure


Procedure calcul(montant.f,taux.f,duree.f)

mensualite.f = montant.f * ((taux.f / 100 / 12) / (1 - Pow(1 + (taux.f / 100),-duree.f * 12)))
cout.f = duree.f * mensualite.f

SetGadgetText(#String_4,StrF(mensualite.f,2))
SetGadgetText(#String_5,StrF(cout.f,2))

EndProcedure

Open_Window_0()

Repeat

evenement = WaitWindowEvent()

Select EventWindow() 
      
      ;===================================================== 
      ;== EVENEMENTS DE LA FENETRE PRINCIPALE 
      ;===================================================== 
      
      Case #Window_0 
        
        Select evenement 
          
          Case #PB_Event_Gadget 
            
            If EventGadget() = #String_0 Or EventGadget() = #String_1 Or EventGadget() = #String_2
              If GetGadgetText(#String_0) <> "0" And GetGadgetText(#String_1) <> "0" And GetGadgetText(#String_2) <> "0"
                calcul(ValF(GetGadgetText(#String_0)), ValF(GetGadgetText(#String_1)), ValF(GetGadgetText(#String_2)))
              EndIf
            EndIf
          
          Case #PB_Event_CloseWindow
          
          End
          
        EndSelect
        
EndSelect

ForEver
:?: :?: :?: :?: :?:

Merci beaucoup à celui ou celle qui m'expliquera pourquoi ca ne fonctionne pas :!: :!: :!:
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

cette formule fonctionne très bien en tout cas :

Code : Tout sélectionner

Procedure.f Mensualite1(MontantEmprunt.f, Taux.f, NbPeriodes.f)
  ProcedureReturn ( MontantEmprunt * ( Taux / ( 1 - Pow( ( 1 + Taux ), -NbPeriodes) ) ) )
EndProcedure

Procedure.f Mensualite2(MontantEmprunt.f, Taux.f, NbAnnee.f)
  ProcedureReturn Mensualite1(MontantEmprunt, Taux / 100 / 12, NbAnnee * 12)
EndProcedure

Debug StrF(Mensualite1(10000, 0.005, 48), 2)
Debug StrF(Mensualite2(10000, 6, 4), 2)
dans ton code tu fais : (taux.f / 100 / 12) puis (taux.f / 100)
dans le dernier tu semble donc oublier la division par 12.
Image
pastor
Messages : 54
Inscription : sam. 14/avr./2007 22:59

Message par pastor »

Bonjour,

Je me suis permis quelques améliorations, voici le code complet :

Code : Tout sélectionner

Enumeration 
  #Window_0 
EndEnumeration 

Enumeration 
  #Text_0 
  #Text_1 
  #Text_2 
  #String_0 
  #String_1 
  #String_2 
  #Text_3 
  #Text_4 
  #Text_5
  #Frame3D_0 
  #Frame3D_1 
  #String_4 
  #String_5
  #String_6
  #Text_6 
EndEnumeration 


Global FontID1 
FontID1 = LoadFont(1, "Arial", 26, #PB_Font_Bold) 


Procedure Open_Window_0() 
  If OpenWindow(#Window_0, 216, 0, 430, 320, "Logibanque",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar ) 
    If CreateGadgetList(WindowID(#Window_0)) 
      TextGadget(#Text_0, 0, 85, 200, 20, "Somme empruntée", #PB_Text_Right) 
      TextGadget(#Text_1, 0, 115, 200, 20, "Taux d'intérêt (en %)", #PB_Text_Right) 
      TextGadget(#Text_2, 0, 145, 200, 20, "Durée de l'emprunt (en années)", #PB_Text_Right) 
      StringGadget(#String_0, 250, 80, 150, 20, "0") 
      StringGadget(#String_1, 250, 110, 150, 20, "0") 
      StringGadget(#String_2, 250, 140, 150, 20, "0") 
      TextGadget(#Text_3, 0, 205, 200, 20, "Remboursement mensuel", #PB_Text_Right) 
      TextGadget(#Text_4, 0, 235, 200, 20, "Coût de l'emprunt", #PB_Text_Right)
      TextGadget(#Text_5, 0, 265, 200, 20, "Montant total remboursé", #PB_Text_Right) 
      Frame3DGadget(#Frame3D_0, 20, 65, 390, 110, "Paramétres d'emprunt") 
      Frame3DGadget(#Frame3D_1, 20, 185, 390, 110, "Valeurs calculées") 
      StringGadget(#String_4, 250, 200, 150, 20, "0", #PB_String_ReadOnly) 
      StringGadget(#String_5, 250, 230, 150, 20, "0", #PB_String_ReadOnly)
      StringGadget(#String_6, 250, 260, 150, 20, "0", #PB_String_ReadOnly) 
      TextGadget(#Text_6, 80, 10, 250, 50, "Logibanque", #PB_Text_Center) 
      SetGadgetFont(#Text_6, FontID1) 
      
    EndIf 
  EndIf 
EndProcedure 


Procedure calcul(montant.f,taux_annuel.l,duree_annees.l) 

nb_periodes.l=duree_annees*12

taux_mens.f=(taux_annuel/100)/12

puissance.f=Pow( ( 1 + taux_mens), -nb_periodes)

mensualite.f=montant * ( taux_mens / ( 1 - puissance ) )

montant_total.f = nb_periodes * mensualite

cout.f=montant_total-(ValF(GetGadgetText(#String_0)))

SetGadgetText(#String_4,StrF(mensualite.f,2)) 
SetGadgetText(#String_5,StrF(cout.f,2)) 
SetGadgetText(#String_6,StrF(montant_total,2)) 

EndProcedure 

Open_Window_0() 

Repeat 

evenement = WaitWindowEvent() 

Select EventWindow() 
      
      ;===================================================== 
      ;== EVENEMENTS DE LA FENETRE PRINCIPALE 
      ;===================================================== 
      
      Case #Window_0 
        
        Select evenement 
          
          Case #PB_Event_Gadget 
            
            If EventGadget() = #String_0 Or EventGadget() = #String_1 Or EventGadget() = #String_2 
              If GetGadgetText(#String_0) <> "0" And GetGadgetText(#String_1) <> "0" And GetGadgetText(#String_2) <> "0" 
                calcul(ValF(GetGadgetText(#String_0)), ValF(GetGadgetText(#String_1)), ValF(GetGadgetText(#String_2))) 
              EndIf 
            EndIf 
          
          Case #PB_Event_CloseWindow 
          
          End 
          
        EndSelect 
        
EndSelect 

ForEver 
A+

Laurent
ThoT
Messages : 33
Inscription : mar. 20/mars/2007 17:51

Message par ThoT »

Merci beaucoup pour votre aide!
Ca marche nickel :D
Répondre