Ad
Code
Diff
  • #include <iostream>
    using namespace std;
    
    string die() {
      return "Invalid Input!";
    }
    
    string Calculator(int choice, int x, int y) {
        string answer;
        if (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5){
            switch (choice) {
            case 1:        
                   answer = std::to_string(x + y);
                   break;
            case 2:        
                   answer = std::to_string(x - y);
                   break; 
            case 3:        
                   answer = std::to_string(x * y);
                   break;
            case 4:        
                   answer = std::to_string(x / y);
                   break;
            case 5:        
                   answer = std::to_string(x % y);
                   break;
            }
        }
        else { return die(); }
    return answer;
    }
    • #include <iostream>
    • using namespace std;
    • 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();
    • string answer;
    • if (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5){
    • switch (choice) {
    • case 1:
    • answer = std::to_string(x + y);
    • break;
    • case 2:
    • answer = std::to_string(x - y);
    • break;
    • case 3:
    • answer = std::to_string(x * y);
    • break;
    • case 4:
    • answer = std::to_string(x / y);
    • break;
    • case 5:
    • answer = std::to_string(x % y);
    • break;
    • }
    • }
    • else { return die(); }
    • return answer;
    • }