Les Allergies
Alimentaires
Posez votre question Signaler

Division par 0 en C++ avec C ++ buider [Résolu]

alcOol 9Messages postés 6 mars 2008Date d'inscription - Dernière réponse le 2 avril 2008 à 16:05
Bonjour,
Alors voila mon problème, j'ai "créé" ma propre calculatrice et j'aimerai que la division par zéro soit interdite. Mais je n'ai rien appris qui pourrait me le permettre quelqu'un pourrait t'il m'aider? Merci d'avance et bonen fin de journée.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include "ufmMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfmMain *fmMain;
char cMonNombre[20];
float iNombre1=0;
float iNombre2=0;
float fResultat=0;
bool bAddition = false;
bool bSoustraction = false;
bool bMultiplication = false;
bool bDivision = false;
void __fastcall TfmMain::bu8Click(TObject *Sender)
{
StrCat(cMonNombre,bu8->Caption.c_str());
edAffichage->Text= cMonNombre;
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::bu9Click(TObject *Sender)
{
StrCat(cMonNombre,bu9->Caption.c_str());
edAffichage->Text= cMonNombre;
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::buPlusClick(TObject *Sender)
{
bAddition=true;
sprintf(cMonNombre,edAffichage->Text.c_str());
iNombre1 = StrToInt(cMonNombre);
edAffichage->Text="";
sprintf(cMonNombre,edAffichage->Text.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::buEgalClick(TObject *Sender)
{
sprintf(cMonNombre,edAffichage->Text.c_str());
iNombre2 = StrToInt(cMonNombre);
sprintf(cMonNombre,buDeco0->Caption.c_str());
if (bAddition==true)
{
fResultat=iNombre1 + iNombre2;
edAffichage->Text = fResultat;
}
if (bSoustraction==true)
{
fResultat=iNombre1 - iNombre2;
edAffichage->Text = fResultat;
}
if (bMultiplication==true)
{
fResultat=iNombre1 * iNombre2;
edAffichage->Text = fResultat;
}
if (bDivision==true)
{
fResultat=iNombre1 / iNombre2;
edAffichage->Text = fResultat;
}
bAddition = false;
bSoustraction = false;
bMultiplication = false;
bDivision = false;
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::buMoinsClick(TObject *Sender)
{
bSoustraction=true;
sprintf(cMonNombre,edAffichage->Text.c_str());
iNombre1 = StrToInt(cMonNombre);
edAffichage->Text="";
sprintf(cMonNombre,edAffichage->Text.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::buFoisClick(TObject *Sender)
{
bMultiplication=true;
sprintf(cMonNombre,edAffichage->Text.c_str());
iNombre1 = StrToInt(cMonNombre);
edAffichage->Text="";
sprintf(cMonNombre,edAffichage->Text.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TfmMain::buDiviserClick(TObject *Sender)
{
bDivision=true;
sprintf(cMonNombre,edAffichage->Text.c_str());
iNombre1 = StrToInt(cMonNombre);
edAffichage->Text="";
sprintf(cMonNombre,edAffichage->Text.c_str());
}
//---------------------------------------------------------------------------
Pour les premiers nombres je ne les ais pas mis mais ils sont pareils aux derniers.
Merci d'avoir pris du temps pour me lire.
Lire la suite 

Division par 0 en C++ avec C ++ buider »

2 réponses
Réponse
+1
moins plus
void __fastcall TfmMain::buEgalClick(TObject *Sender)
{ .....
....
if (bDivision==true)
{
if(iNomre2 != 0)
{fResultat=iNombre1 / iNombre2;
edAffichage->Text = fResultat;
}
else
edAffichage->Text = "Erreur Division par 0";
}
alcOol- 2 avril 2008 à 16:05
void __fastcall TfmMain::buEgalClick(TObject *Sender)
{ .....
....
if (bDivision==true)
{
if(iNombre2 != 0)
{fResultat=iNombre1 / iNombre2;
edAffichage->Text = fResultat;
}
else
edAffichage->Text = "Erreur Division par 0";
}

merci pour ton aide
Ajouter un commentaire
Ce document intitulé « Division par 0 en C++ avec C ++ buider » issu de CommentCaMarche (www.commentcamarche.net) est mis à disposition sous les termes de la licence Creative Commons. Vous pouvez copier, modifier des copies de cette page, dans les conditions fixées par la licence, tant que cette note apparaît clairement.
Dossier à la une
Passage au tout numérique : quel coût pour les particuliers ?