Division par 0 en C++ avec C ++ buider
Résolu
alcOol
Messages postés
9
Date d'inscription
Statut
Membre
Dernière intervention
-
alcOol Messages postés 9 Date d'inscription Statut Membre Dernière intervention -
alcOol Messages postés 9 Date d'inscription Statut Membre Dernière intervention -
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.
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.
A voir également:
- ++0
- Remettre a 0 un pc - Guide
- Numéro de téléphone excel 0 - Guide
- 0 barré clavier ✓ - Forum Programmation
- Excel différent de 0 ✓ - Forum Excel
- Code ascii de 0 - Guide
{ .....
....
if (bDivision==true)
{
if(iNombre2 != 0)
{fResultat=iNombre1 / iNombre2;
edAffichage->Text = fResultat;
}
else
edAffichage->Text = "Erreur Division par 0";
}
merci pour ton aide