Bonsoir tout le monde,
J'ai un petit problème dans le code ci dessous.
C'est un petit test de calcul que j'essaye de faire fonctionner pour le moment je le teste qu'avec trois chiffres et 2 opérations.
Donc le premier calcul fonctionne correctement mais là où ça se corse c'est après le égal.
exemple : 1+1 = 2 là ça marche
mais quand je fais 1+1 = 2 +1... là ça me met des mauvais résultats !
En fait un (+) ou un (-) après le résultat ça me donne un résultat bizarre.
char AffichageEdit[25]; ----------->affichage dans l'Edit1
int Operation=0;-----------------> indicateur de l’opération
char EffaceChaine[25];-----------> remet l'Edit1 à vide apres un clic sur le +
int Memoir1;---------------------> mémorise le 1er affichage
int Memoir2;---------------------> mémorise le 2eme affichage
int Resultat;---------------------> Résultat
int ResMemoir;
Vous auriez une idée svp?
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
76
77
78
79
80
81 #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; char AffichageEdit[25]; int Operation=0; char EffaceChaine[25]; int Memoir1; int Memoir2; int Resultat; int ResMemoir; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton1Click(TObject *Sender) { StrCat(AffichageEdit,"1"); Edit1->Text= AffichageEdit; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton2Click(TObject *Sender) { StrCat(AffichageEdit,"2"); Edit1->Text=AffichageEdit; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton3Click(TObject *Sender) { StrCat(AffichageEdit,"3"); Edit1->Text=AffichageEdit; } //--------------------------------------------------------------------------- void __fastcall TForm1::aditionClick(TObject *Sender) { Operation=1; Memoir1=StrToInt(AffichageEdit)+ Resultat; StrCopy(AffichageEdit,EffaceChaine); Edit1->Text=AffichageEdit; } //--------------------------------------------------------------------------- void __fastcall TForm1::egaleClick(TObject *Sender) { if(Operation==1){ Memoir2=StrToInt(AffichageEdit) ; Resultat=Memoir1 + Memoir2; Edit1->Text=Resultat; } if(Operation==2){ Memoir2=StrToInt(AffichageEdit); Resultat=Memoir1 - Memoir2; Edit1->Text=Resultat; } } //--------------------------------------------------------------------------- void __fastcall TForm1::soustractionClick(TObject *Sender) { Operation=2; Memoir1=StrToInt(AffichageEdit); StrCopy(AffichageEdit,EffaceChaine); Edit1->Text=AffichageEdit; }
Partager