Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions exercises/calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,28 @@
Multiplication: 8
Division: 2
*/
#include <iostream>
#include <iomanip>

int main() {
double num1, num2;

std::cout << "Insert first number: ";
std::cin >> num1;

std::cout << "Insert second number: ";
std::cin >> num2;

std::cout << "SUM: " << num1 + num2 << std::endl;
std::cout << "Difference: " << num1 - num2 << std::endl;
std::cout << "Multiplication: " << num1 * num2 << std::endl;

if (num2 != 0) {
std::cout << "Division: " << std::fixed << std::setprecision(2) << num1 / num2 << std::endl;
} else {
std::cout << "Division: Cannot divide by zero" << std::endl;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potresti estrarre l'implementazione in una funzione a parte


return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 è poco significativo, potresti usare un #define EXIT_SUCCESS 0 e sostituire questo "magic number"

}