Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Example/1_HelloWorld.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Project 1: Hello World Program
* Author: Your Name
Copy link
Owner Author

Choose a reason for hiding this comment

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

add author and date

* Date: YYYY-MM-DD
* Author: Bocaletto Luca
* Date: 2025-06-22
*
* Description:
* This simple program demonstrates the fundamental structure of a C program.
Expand Down
68 changes: 68 additions & 0 deletions Example/2_SimpleCalculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copy link
Owner Author

Choose a reason for hiding this comment

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

bug fix name file

* Project 2: Simple Calculator
* Author: Bocaletto Luca
* Date: 2025-06-22
*
* Description:
* This program functions as a simple calculator capable of performing basic
* arithmetic operations: addition, subtraction, multiplication, and division.
* It prompts the user for two numbers and an operator, then computes and displays the result.
*
* Key Concepts:
* - Standard input/output using scanf() and printf()
* - Conditional statements (if/else) for operation selection
* - Basic error checking (e.g., preventing division by zero)
*/

#include <stdio.h> // Standard I/O library for input and output functions

int main(void) {
// Declare variables to store two numeric inputs and the result.
double num1, num2, result;

// Declare a variable to store the arithmetic operator.
char operator;

// Prompt the user to enter the first number.
printf("Enter first number: ");
scanf("%lf", &num1); // Read a floating-point number from the user

// Prompt the user to enter an operator.
// The leading space in " %c" helps to skip any leftover whitespace.
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);

// Prompt the user to enter the second number.
printf("Enter second number: ");
scanf("%lf", &num2);

// Use conditional statements to perform the appropriate arithmetic operation based on the operator.
if (operator == '+') {
// Addition operation
result = num1 + num2;
printf("%.2lf + %.2lf = %.2lf\n", num1, num2, result);
} else if (operator == '-') {
// Subtraction operation
result = num1 - num2;
printf("%.2lf - %.2lf = %.2lf\n", num1, num2, result);
} else if (operator == '*') {
// Multiplication operation
result = num1 * num2;
printf("%.2lf * %.2lf = %.2lf\n", num1, num2, result);
} else if (operator == '/') {
// Division operation: check for division by zero.
if (num2 == 0) {
// Print an error message if num2 is zero.
printf("Error: Division by zero is not allowed.\n");
} else {
result = num1 / num2;
printf("%.2lf / %.2lf = %.2lf\n", num1, num2, result);
}
} else {
// Print an error message for an unrecognized operator.
printf("Error: Unknown operator '%c'\n", operator);
}

// Return 0 to indicate that the program executed successfully.
return 0;
}