Ad

#include
using namespace std;

int faiAddizione(int x, int y);
int faiSottrazione(int x, int y);
int faiMoltiplicazione(int x, int y);
int faiDivisione(int x, int y);
int faiModulus(int x, int y);

string die() {
return "Invalid Input!";
}

string Calculator(int choice, int x, int y) {
cout << "Welcome to simple calculator!\n";
cout << "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\n";
// YOU: Write code to finish this program (Input is given, don't use cin)

switch(choice){
    case 1 : cout << faiAddizione(x, y);
      break;
    case 2 : cout << faiSottrazione(x, y);
      break;
    case 3 : cout << faiMoltiplicazione(x, y);
      break;
    case 4 : cout << faiDivisione(x, y);
      break;
    case 5 : cout << faiModulus(x,y);
      break;
    default : die();
}

// Instead of cout << x + y << endl; for example, do return (x + y);
// You can call the die function with die();

}

int faiAddizione(int x, int y)
{ return (x + y);

}

int faiSottrazione(int x, int y){
return (x - y);

}

int faiDivisione(int x, int y){
if(y != 0){
return (x/y);
}
else
{
die();
return 0;
}
}

int faiMoltiplicazione(int x, int y){
return (x * y);
}

int faiModulus(int x, int y){
return (x % y);
}

Code
Diff
  • #include <iostream>
    using namespace std;
    
    int faiAddizione(int x, int y);
    int faiSottrazione(int x, int y);
    int faiMoltiplicazione(int x, int y);
    int faiDivisione(int x, int y);
    int faiModulus(int x, int y);  
    
    
    string die() {
      return "Invalid Input!";
    }
    
    string Calculator(int choice, int x, int y) {
        cout << "Welcome to simple calculator!\n";
        cout << "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\n";
        // YOU: Write code to finish this program (Input is given, don't use cin)
        
        switch(choice){
            case 1 : cout << faiAddizione(x, y);
              break;
            case 2 : cout << faiSottrazione(x, y);
              break;
            case 3 : cout << faiMoltiplicazione(x, y);
              break;
            case 4 : cout << faiDivisione(x, y);
              break;
            case 5 : cout << faiModulus(x,y);
              break;
            default : return die();
                break;
        }
    }  
    
    
    int faiAddizione(int x, int y)
      { return (x + y);
      
    }
    
    int faiSottrazione(int x, int y){
      return (x - y);
      
    }
    
      
      int faiDivisione(int x, int y){
      if(y != 0){
        return (x/y);
      }
      else
      {
        die();
        return 0;
      }
    }
    
      
      int faiMoltiplicazione(int x, int y){
      return (x * y); 
    }
    
      
      int faiModulus(int x, int y){
      return (x % y);
    }
    
    • #include <iostream>
    • using namespace std;
    • int faiAddizione(int x, int y);
    • int faiSottrazione(int x, int y);
    • int faiMoltiplicazione(int x, int y);
    • int faiDivisione(int x, int y);
    • int faiModulus(int x, int y);
    • string die() {
    • return "Invalid Input!";
    • }
    • string Calculator(int choice, int x, int y) {
    • cout << "Welcome to simple calculator!\n";
    • cout << "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\n";
    • // YOU: Write code to finish this program (Input is given, don't use cin)
    • // Instead of cout << x + y << endl; for example, do return (x + y);
    • // You can call the die function with die();
    • }
    • switch(choice){
    • case 1 : cout << faiAddizione(x, y);
    • break;
    • case 2 : cout << faiSottrazione(x, y);
    • break;
    • case 3 : cout << faiMoltiplicazione(x, y);
    • break;
    • case 4 : cout << faiDivisione(x, y);
    • break;
    • case 5 : cout << faiModulus(x,y);
    • break;
    • default : return die();
    • break;
    • }
    • }
    • int faiAddizione(int x, int y)
    • { return (x + y);
    • }
    • int faiSottrazione(int x, int y){
    • return (x - y);
    • }
    • int faiDivisione(int x, int y){
    • if(y != 0){
    • return (x/y);
    • }
    • else
    • {
    • die();
    • return 0;
    • }
    • }
    • int faiMoltiplicazione(int x, int y){
    • return (x * y);
    • }
    • int faiModulus(int x, int y){
    • return (x % y);
    • }