Cree un programme avec l instruction switch

Résolu/Fermé
merry - 21 nov. 2010 à 20:10
 merry - 21 nov. 2010 à 20:48
Bonjour,
j'ai fait un programme avec l instruction if-else et j'ai essayé de le faire avec l instruction switch mais j'arrive pas ; Pouvez-vous m'aider ?

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
char op;
int m,n;
cout<<" entrer 2 entier m et n \n";
cin>>m;
cin>>n;
cout<<"l operation est ";
cin>>op;

if(op=='+') cout<<m <<"+" <<n<<" = "<<m+n;
else if(op=='-') cout<<m <<"-" <<n<<" = "<<(m-n);
else if(op=='*') cout<<m <<"*"<< n<<" = "<<m*n;
else if(op=='/')cout<<m <<"/"<< n<<" = "<<m/n;
getch();
}



A voir également:

2 réponses

fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 835
21 nov. 2010 à 20:16
Bonjour,
En C++, on n'inclut pas iostream.h mais iostream.
Pas besoin de iomanip pour ton code.

Sinon, pour le switch :
switch (op) {
 case '+' :
    ...
    ...
    break;
 case '-' :
   ...


}

Cdlt,
0
MERCI
0