Advertisement
Guest User

Programma test 1

a guest
Mar 5th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <IOstream>
  2.  
  3. using namespace std;
  4.  
  5. int a;
  6. int b;
  7. //operazione = op
  8. int op;
  9. int r;
  10.  
  11. int main() {
  12.     //user input
  13.     cout<<"Insert a:"<<endl;
  14.     cin>>a;
  15.     cout<<"Insert b:"<<endl;
  16.     cin>>b;
  17.     cout<<"scegli l'operazione:"<<endl;
  18.     cout<<"1 = Addizione"<<endl;
  19.     cout<<"2 = Sottrazione"<<endl;
  20.     cout<<"3 = Moltiplicazione"<<endl;
  21.     cout<<"4 = Divisione"<<endl;
  22.     cin>>op;
  23.     //controllo operazione
  24.     if (op == 1){
  25.            r = a+b;
  26.            cout<<"Risultato:"<<r<<endl;}
  27.     else if (op == 2){
  28.           r = a-b;
  29.           cout<<"Risultato:"<<r<<endl;}
  30.        else if (op == 3) {
  31.               r = a*b;
  32.               cout<<"Risultato:"<<r<<endl;}
  33.            else if (op == 4) {
  34.                 if (a>=b){
  35.                   r =a/b;
  36.                       cout<<"Risultato:"<<r<<endl;}
  37.                   else {
  38.                        cout<<"impossibile dividere: divisore maggiore del dividendo"<<endl;}
  39.                        }
  40.                  else {
  41.                       cout<<"Errore: numero di operazione non riconosciuto"<<endl;}
  42.     system("pause");
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement