#include <iostream.h> //--------------------------------------------------------------------------- bool chaineInt(const char *chaine, int &entier) { bool correcte=true, negatif=false; entier=0; for (int i=0; chaine[i]; i++) { entier *= 10; if (chaine[i]<'0' || chaine[i]>'9') if (chaine[i]=='-') { negatif=true; continue; } else { correcte=false; break; } entier += chaine[i]-0x30; } if (negatif) entier = -entier; return correcte; } //--------------------------------------------------------------------------- int main(int argc, char* argv[]) { if (argc==4) { int operande1, operande2; if (!chaineInt(argv[1], operande1)) { cout << "le premier operande n'est pas bon"; return -1; } if (!chaineInt(argv[3], operande2)) { cout << "le deuxieme operande n'est pas bon"; return -1; } cout << "Resultat du calcul : "; switch (argv[2][0]) { case '+' : cout << operande1+operande2; break; case '-' : cout << operande1-operande2; break; case '*' : cout << operande1*operande2; break; case '/' : if (!operande2) { cout << "Attention division par zero"; return -1; } cout << operande1/operande2; break; } return 0; } else { cout << "Nombre d'arguments incorrect"; return -1; } } //---------------------------------------------------------------------------