IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

Problème d'exposant sur une méthode mathématique.


Sujet :

Delphi

  1. #1
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut Problème d'exposant sur une méthode mathématique.
    Bonjour,
    J'espere quevous pourrez m'aider ... car j'ai un petit souçi ....
    je vous explique je developpe un petit utilitaire de calculs pour des credits ...
    pour facilite ma tache au boulot ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    procedure Tform1.Button3Click(Sender: TObject);
     
    function intPower(Base: extended; Exponent: extended): extended;
     
    var
          f,g,h:
          real;
    begin
        f :=StrToFloat(montant.Text);
        g :=StrToFloat(pourcentage.Text);
        h :=StrToFloat(duree.Text);
     
       f:=intpower (f,f+1); <= voilà mon problème... comment faire fonctionner la fonction power ou intpower afin de calculer mon exposant ... ?
     
          interetmensuel.caption:= floattostr ((1+g)^(g/12)-1); 
    //bad      interetmensuel.caption:= floattostr ;
          primemens.caption:=FloatToStr (f);
     
     
      end;
      end.
    voilà mon problème... comment faire fonctionner la fonction power ou intpower afin de calculer mon exposant ... j'espere que vous pourrez m'éclairer un peu ... ou me mettre sur la voie ...

    merci :p

  2. #2
    Inactif  
    Inscrit en
    Mars 2006
    Messages
    352
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 352
    Points : 292
    Points
    292
    Par défaut
    Bonsoir,
    as-tu inclu l'unité math dans la partie uses ?
    Bon cour@ge.

  3. #3
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut
    oui c'est fait ... mais ca ne fonctionne pas ... :s je vais mettre le code entier de mon applic pour avoir plus facile ...
    unit Unit1;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, math;
     
     
    type
      Tform1 = class(TForm)
        edit1: TEdit;
        edit2: TEdit;
        somme: TLabel;
        Button1: TButton;
        soustra: TLabel;
        division: TLabel;
        multi: TLabel;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        edit3: TEdit;
        Racine: TLabel;
        Label7: TLabel;
    //  Button2: TButton;
        montant: TEdit;
        pourcentage: TEdit;
        pourcenlabel: TLabel;
        Label6: TLabel;
    //  Button1: TButton;
        Prime: TLabel;
        primemens: TLabel;
        interetmensuel: TLabel;
        Label8: TLabel;
        Label5: TLabel;
        duree: TEdit;
        Label9: TLabel;
     
        procedure Button1Click(Sender: TObject);
     
     
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
     
      form1: Tform1;
     
    implementation
     
    {$R *.dfm}
     
     
    procedure Tform1.Button1Click(Sender: TObject);
     
    function intPower(Base: extended; Exponent: extended): extended;
     
    var
          f,g,h:
          real;
    begin
        f :=StrToFloat(montant.Text);
        g :=StrToFloat(pourcentage.Text);
        h :=StrToFloat(duree.Text);
    //   f:=intpower (f,f+1);
     
        interetmensuel.caption:= floattostr((1+g)^(g/12)-1);
        primemens.caption:=FloatToStr ((f/h)*(g/12)+1);
     
     
      end;
      end.
    voili, voilà... ?

  4. #4
    Inactif  
    Inscrit en
    Mars 2006
    Messages
    352
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 352
    Points : 292
    Points
    292
    Par défaut
    Salut,
    je crois que cette ligne qui pose problème :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    interetmensuel.caption:= floattostr((1+g)^(g/12)-1);
    Y a pas l'opérateur puissance ^ dans Delphi, mais Power ou IntPower.
    J'attends ta réponse, à bientôt.

  5. #5
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut
    ben voui je l'ai renseignée un peu plus haut la intpower ... mais je ne sais pas comment la présentée j'ai du mal en fait

    calculx.zipvoici les codes sources et tout et tout ... :s

  6. #6
    Inactif  
    Inscrit en
    Mars 2006
    Messages
    352
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 352
    Points : 292
    Points
    292
    Par défaut
    Bonsoir,
    voilà mon ami, une petite aide :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      math ;
     
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.DFM}
     
    procedure TForm1.FormCreate(Sender: TObject);
    var
      f, g, h, res, res2 : real;
    begin
      f := 2.0;
      g := 3.0;
      h := 4.0;
      f := power(f, f + 1);
      res := power(1 + g, g / 12);
      res := res - 1;
      res2 := (f / h) * (g / 12) + 1;
      {interetmensuel.caption:= floattostr((1+g)^(g/12)-1);
      primemens.caption:=FloatToStr ((f/h)*(g/12)+1);}
      ShowMessage('f = ' + FloatToStr(f));
      ShowMessage('res = ' + FloatToStr(res));
      ShowMessage('res2 = ' + FloatToStr(res2));
    end;
     
    end.
    j'espère avoir t'aider, bon courage.

  7. #7
    Rédacteur
    Avatar de evarisnea
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2005
    Messages
    1 957
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2005
    Messages : 1 957
    Points : 4 384
    Points
    4 384
    Par défaut

    Citation Envoyé par ecobarito Voir le message
    ben voui je l'ai renseignée un peu plus haut la intpower ... mais je ne sais pas comment la présentée j'ai du mal en fait
    ecobarito je te souhaite la bienvenue sur le forum des développeurs, et je te conseille si ce n'est déjà fait de lire ceci.
    en effet pour ton souci, un petit sur intpower ou power aurait suffit je trouve.

  8. #8
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut
    Merci beaucoup :d
    ben alors faut croire que je suis un imbécile ... cela fait 15 ans que je rôde de forum en forum pour divers activitées mais on ne m'avait jamais fait une remarque comme celle là ... de plus lorsque je cherche dans l'aide de delphi (qui est un peu nulle ...) je n'ai eu que ceci comme resultat ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    function intPower(Base: extended; Exponent: extended): extended;
    qui de plus apparait n'etre pas la bonne fonction ...

  9. #9
    Membre confirmé
    Avatar de OutOfRange
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    533
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 533
    Points : 474
    Points
    474
    Par défaut
    Salut
    Moi j'ai ça (Aide Delphi 6 perso)
    IntPower, fonction

    Calcule la puissance entière d'une valeur de base.

    Unité

    Math

    Catégorie

    routines arithmétiques

    function IntPower(const Base: Extended; const Exponent: Integer): Extended register;

    Description

    IntPower élève Base à la puissance spécifiée par Exponent.
    Donc IntPower(2,3) renvoie "2^3" soit 8

    Pour manipuler des puissances non entières, power est ce qu'il te faut ("2^0.5" par ex)
    Choisir, c'est renoncer...

  10. #10
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    procedure Tform1.Button3Click(Sender: TObject);
     
    var
      f, g, h, res, res2 : real;
     
    begin
      f := 2.0;
      g := 3.0;
      h := 4.0;
      f := power(f, f + 1);
      res := power(1 + g, g / 12);
      res := res - 1;
      res2 := (f / h) * (g / 12) + 1;
      {interetmensuel.caption:= floattostr((1+g)^(g/12)-1);
      primemens.caption:=FloatToStr ((f/h)*(g/12)+1);}
      ShowMessage('f = ' + FloatToStr(f));
      ShowMessage('res = ' + FloatToStr(res));
      ShowMessage('res2 = ' + FloatToStr(res2));
    end;
    Je dispose de 3 champs tedit qui contiendront les valeurs (ex: 200000€ pour le montant du crédit , 5,25% pour le taux d'interet annuel , X mois pour la duree ex: 20 ans = 240 mois) et j'ai aussi 2 tlabel, un nommé primemens et l'autre interetmensuel dans lesquels j'aurai voulu afficher mes resultats ... je ne vois pas ou je dois inserer dans ce code ces variable là ... désolé de mon noobisme :s ... :p
    j'ai regarde dans l'aide de mon delphi 2007 ... mais je ne trouve aucun exemple représentatif ...
    merci de vos réponses :p

  11. #11
    Membre confirmé
    Avatar de OutOfRange
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    533
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 533
    Points : 474
    Points
    474
    Par défaut
    Sers toi de FloatToStr pour changer la propriété caption de tes TLabel
    Choisir, c'est renoncer...

  12. #12
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut
    ce code ci me renvoi une erreur
    je pense que l'erreur vient du fait qu'il y aurait trop de chiffre apres la virgule ...
    Exception déclenchée à $7C81EB33. Classe d'exception EOverflow avec message 'Floating point overflow'. Processus Project2.exe (984)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    procedure Tform1.Button3Click(Sender: TObject);
     
    var
      f, g, h, res, res2 : real;
     
    begin
      f := StrToFloat(montant.Text);
      g := StrToFloat(pourcentage.Text);
      h := StrToFloat(duree.Text);
      f := power(f, f + 1);
      res := power(1 + g, g / 12);
      res := res - 1;
      res2 := (f / h) * (g / 12) + 1;
     
    primemens.caption:=  FloatToStr(res);
    interetmensuel.caption:=  FloatToStr(res2)
      // ShowMessage('f = ' + FloatToStr(f));
      //ShowMessage('res = ' + FloatToStr(res));
      //ShowMessage('res2 = ' + FloatToStr(res2));
    end;

  13. #13
    Inactif  
    Inscrit en
    Mars 2006
    Messages
    352
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 352
    Points : 292
    Points
    292
    Par défaut
    Bonsoir,
    non, ça marche parfaitement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      math, StdCtrls ;
     
    type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        procedure FormCreate(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.DFM}
     
    procedure TForm1.FormCreate(Sender: TObject);
    var
      f, g, h, res, res2 : real;
    begin
      f := 2.0;
      g := 3.0;
      h := 4.0;
      f := power(f, f + 1);
      res := power(1 + g, g / 12);
      res := res - 1;
      res2 := (f / h) * (g / 12) + 1;
      {interetmensuel.caption:= floattostr((1+g)^(g/12)-1);
      primemens.caption:=FloatToStr ((f/h)*(g/12)+1);}
      Label1.Caption := FloatToStr(res);
      Label2.Caption := FloatToStr(res2);
      {ShowMessage('f = ' + FloatToStr(f));
      ShowMessage('res = ' + FloatToStr(res));
      ShowMessage('res2 = ' + FloatToStr(res2));}
    end;
     
    end.
    Bon cour@ge.

  14. #14
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 26
    Points : 14
    Points
    14
    Par défaut
    ben ici je dois bien mettre le nom de mes tedit ???
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    f := StrToFloat(montant.Text);
      g := StrToFloat(pourcentage.Text);
      h := StrToFloat(duree.Text);
    toi tu met ceci ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      f := 2.0;
      g := 3.0;
      h := 4.0;
    pourquoi ?

  15. #15
    Inactif  
    Inscrit en
    Mars 2006
    Messages
    352
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 352
    Points : 292
    Points
    292
    Par défaut
    Rebonsoir,
    Oui, j'ai fait ça juste pour t'expliquer que ça marche, sinon tu mets tes TEdit.
    Au revoir.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème de thread sur une méthode d'une classe C++
    Par yoshi84300 dans le forum Threads & Processus
    Réponses: 5
    Dernier message: 12/03/2013, 11h23
  2. Problème d'exécution d'une méthode sur le server
    Par SonnyFab dans le forum ASP.NET
    Réponses: 2
    Dernier message: 06/08/2010, 13h00
  3. Réponses: 6
    Dernier message: 24/03/2009, 16h17
  4. Problème return sur une méthode
    Par root76 dans le forum Langage
    Réponses: 3
    Dernier message: 07/03/2008, 10h43
  5. Réponses: 3
    Dernier message: 16/04/2004, 16h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo