non me ne frega se hai trovato questa pagina
[cpp]
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::stringstream;
using std::setprecision;
using std::fixed;
string removeCommasAndPoints(string str) {
string result = “”;
for (char c : str) {
if (c >= ‘0’ && c <= ‘9’) {
result += c;
}
}
return result;
}
int main() {
char op;
string num1_str, num2_str;
char chiudi;
bool processo = true;
do
{
cout << “Inserisci primo numero: “;
cin >> num1_str;
cout << “Inserisci operatore (+, -, *, /): “;
cin >> op;
cout << “Inserisci secondo numero: “;
cin >> num2_str;
string num1_clean = removeCommasAndPoints(num1_str);
string num2_clean = removeCommasAndPoints(num2_str);
long double num1 = stold(num1_clean);
long double num2 = stold(num2_clean);
long double result = 0.0;
switch (op) {
case ‘+’:
result = num1 + num2;
break;
case ‘-‘:
result = num1 – num2;
break;
case ‘*’:
result = num1 * num2;
break;
case ‘/’:
if (num2 != 0.0) {
result = num1 / num2;
} else {
cout << “Errore: divisione per zero” << endl;
return 1;
}
break;
default:
cout << “Errore: operatore invalido. ucciditi” << endl;
return 1;
}
stringstream ss;
ss << fixed << setprecision(0) << result;
string result_str = ss.str();
int len = result_str.length();
string formatted_result = “”;
for (int i = 0; i < len; i++) {
formatted_result += result_str[i];
if ((len – i – 1) % 3 == 0 && i != len – 1) {
formatted_result += “.”;
}
}
cout << “Risultato: ” << formatted_result << ‘\n’;
std::cout << “Digita ‘q’ per uscire o qualunque altra cosa per riprendere i calcoli.\n”;
cin >> chiudi;
switch (chiudi)
{
case ‘q’:
processo = false;
break;
case ‘ ‘:
break;
default:
break;
}
} while (processo);
return 0;
}
[/cpp]