Menu

Data: 18/11/2025

Exit

// Importing libs
#include <iostream>

using namespace std;

// FUNCTION DEFINITION
// Show the menu
void showMenu() {
    cout << "           MENU\n\n";
    cout << "[1] Somma algebrica 2 numeri\n";
    cout << "[2] Convertire da Celsius a Fahrenheit\n";
    cout << "[3] Convertire da Fahrenheit a Celsius\n";
    cout << "[4] Ordina 2 numeri in ordine crescente\n";
    cout << "[5] Ordina 2 numeri in ordine decrescente\n";
    cout << "[6] Verifica se un numero è positivo, negativo o nullo\n";
    cout << "[7] Esci\n\n";
}

// Get choice
int getChoice() {
    int c;
    cout << "Scegli cosa fare: ";
    cin >> c;
    
    if (c == 1 || c == 2 || c == 3 || c == 4 || c == 5 || c == 6 || c == 7) {
        return c;
    } else {
        cout << "\nScelta non valida\n";
        showMenu();
        return getChoice();
    }
}

// Make the sum
void sum() {
    float a,b;
    cout << "\nInserisci primo numero: ";
    cin >> a;
    cout << "Inserisci secondo numero: ";
    cin >> b;
    cout << "\nLa somma tra " << a << " e " << b << " è: " << a + b;
}

// Make the conversions
void degConv(bool ord) {
    float a;
    if (ord) {
        cout << "\nInserisci i gradi in Celsius: ";
        cin >> a;
        cout << "\nI gradi in Fahrenheit sono: " << (a * 9/5) + 32 << "°F";
    } else {
        cout << "\nInserisci i gradi in Fahrenheit: ";
        cin >> a;
        cout << "\nI gradi in Celsius sono: " << (a - 32) * 5/9 << "°C";
    }
}

// Make the reorder
void reorder(bool ord) {
    float a,b;
    cout << "\nInserisci il primo numero: ";
    cin >> a;
    cout << "Inserisci il secondo numero: ";
    cin >> b;
    
    if (ord) {
        if (b > a) {
            cout << "\nI numeri riordinati in ordine crescente sono: " << a << ", " << b;
        } else {
            cout << "\nI numeri riordinati in ordine crescente sono: " << b << ", " << a;
        }
    } else {
        if (b > a) {
            cout << "\nI numeri riordinati in ordine decrescente sono: " << b << ", " << a;
        } else {
            cout << "\nI numeri riordinati in ordine decrescente sono: " << a << ", " << b;
        }
    }
}

// Make the verification
void verif() {
    float a;
    cout << "\nInserisci il numero: ";
    cin >> a;
    if (a == 0) {
        cout << "\nIl numero è nullo";
    } else if (a > 0) {
        cout << "\nIl numero è positivo";
    } else {
        cout << "\nIl numero è negativo";
    }
}

// MAIN
int main() {
    showMenu();
    int choice = getChoice();
    
    if (choice == 1) {
        sum();
    } else if (choice == 2) {
        degConv(true);
    } else if (choice == 3) {
        degConv(false);
    } else if (choice == 4) {
        reorder(true);
    } else if (choice == 5) {
        reorder(false);
    } else if (choice == 6) {
        verif();
    } else if (choice == 7) {
        cout << "\n\nBye Bye";
    }
    return 0;
}