-
Notifications
You must be signed in to change notification settings - Fork 0
Test #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Test #2
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add author and date