Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath> // equivale a math.h #include <math.h>
- #include <iostream>
- #define LIMITE_OPERAZIONI 10
- using namespace std;
- int main() {
- int numero_radici = 0;
- int numero_potenze = 0;
- double radici_calcolate[LIMITE_OPERAZIONI];
- double potenze_calcolate[LIMITE_OPERAZIONI];
- int scelta_utente;
- cout << "1) Per calcolare la radice quadrata." << endl;
- cout << "2) Per calcolare la potenza" << endl;
- cout << "0) Per uscire dal programma" << endl;
- cout << "Puoi effettuare un limite di 10 volte ogni operazione" << endl;
- do {
- cout << "Effettua una scelta: ";
- cin >> scelta_utente;
- // Se non devo uscire
- if (scelta_utente != 0) {
- // O devo fare una radice o una potenza
- if (scelta_utente == 1) {
- // Devo fare una radice quadrata
- if (numero_radici < LIMITE_OPERAZIONI) {
- cout << "Hai a disposizione ancora " << LIMITE_OPERAZIONI - numero_radici << " radici." << endl;
- cout << "Inserire numero di cui calcolare la radice quadrata: ";
- double radicando;
- cin >> radicando;
- // Codice che calcola la radice quadrata
- radici_calcolate[numero_radici] = sqrt(radicando);
- numero_radici++;
- } else {
- // Ho superato il limite di operazioni consentite
- cout << "Non puoi più effettuare operazioni di radice quadrata!"
- << endl;
- }
- }
- if (scelta_utente == 2) {
- if (numero_potenze < LIMITE_OPERAZIONI) {
- // Devo fare una potenza
- cout << "Hai a disposizione ancora " << LIMITE_OPERAZIONI - numero_potenze << " potenze." << endl;
- cout << "Inserire base ed esponente: ";
- double base, esponente;
- cin >> base >> esponente;
- // Codice che calcola la potenza
- potenze_calcolate[numero_potenze] = pow(base, esponente);
- numero_potenze++;
- } else {
- cout << "Non puoi più effettuare operazioni di potenza!" << endl;
- }
- }
- }
- } while (scelta_utente != 0);
- cout << "Elenco radici calcolate:" << endl;
- for (int i = 0; i < numero_radici; i++) {
- cout << radici_calcolate[i] << " ";
- }
- cout << endl << "Elenco potenze calcolate:" << endl;
- for (int i = 0; i < numero_potenze; i++) {
- cout << potenze_calcolate[i] << " ";
- }
- cout << endl << "Grazie per aver utilizzato il programma :D" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement