Advertisement
Guest User

es

a guest
Oct 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int addizione(int a, int b){
  5. return a+b;}
  6. int sottrazione(int a, int b){
  7. return a-b;}
  8. int moltiplicazione(int a, int b){
  9. return a*b;}
  10. float divisone(float a, float b){
  11. return a/b;}
  12.  
  13. int main() {
  14. /*stampo il menu*/
  15. double a, b;
  16. int c;
  17. cin>>c;
  18. cout<<"inserisci due numeri: ";
  19. cin >> a;
  20. cin >> b;
  21. cout<<"Seleziona il numero corrispondente all'opzione desiderata: "<<endl;
  22. cout<<" \t menù "<<endl;
  23. cout<<" 1) addizione"<<endl;
  24. cout<<" 2) sottrazione"<<endl;
  25. cout<<" 3) moltiplicazione "<<endl;
  26. cout<<" 4) divisione"<<endl;
  27. cout<<" 0) esci "<<endl;
  28. /*inserisco il valore*/
  29.  
  30. while(c<0 || c>4 ){
  31. cout<<"Hai inserito un valore non valido"<<endl;
  32. cout<<"reinserire un valore corretto (tra 0 e 4): ";
  33. cin>>a;
  34. }
  35.  
  36. switch(c) {
  37. case 0:
  38. break;
  39. case 1:
  40. cout<< addizione(int a,int b); break;
  41.  
  42. case 2:
  43. cout<< sottrazione (int a,int b); break;
  44.  
  45. case 3:
  46. cout<< moltiplicazione(int a,int b);
  47. break;
  48.  
  49. case 4:
  50. if(b==0) {
  51. cout<<"Alla prossima";
  52. exit(-1);
  53. }
  54. cout<< divisione (float a,float b);
  55. break;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement