Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IOstream>
- using namespace std;
- int a;
- int b;
- //operazione = op
- int op;
- int r;
- int main() {
- //user input
- cout<<"Insert a:"<<endl;
- cin>>a;
- cout<<"Insert b:"<<endl;
- cin>>b;
- cout<<"scegli l'operazione:"<<endl;
- cout<<"1 = Addizione"<<endl;
- cout<<"2 = Sottrazione"<<endl;
- cout<<"3 = Moltiplicazione"<<endl;
- cout<<"4 = Divisione"<<endl;
- cin>>op;
- //controllo operazione
- if (op == 1){
- r = a+b;
- cout<<"Risultato:"<<r<<endl;}
- else if (op == 2){
- r = a-b;
- cout<<"Risultato:"<<r<<endl;}
- else if (op == 3) {
- r = a*b;
- cout<<"Risultato:"<<r<<endl;}
- else if (op == 4) {
- if (a>=b){
- r =a/b;
- cout<<"Risultato:"<<r<<endl;}
- else {
- cout<<"impossibile dividere: divisore maggiore del dividendo"<<endl;}
- }
- else {
- cout<<"Errore: numero di operazione non riconosciuto"<<endl;}
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement