Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Project516/c-calc/llms.txt

Use this file to discover all available pages before exploring further.

Interactive mode is the default way to use c-calc. When you run the binary with no arguments, the program guides you through entering a first number, an operator, and a second number before printing the result. This page walks through each prompt in order and explains what happens when input is invalid or the operator is unrecognized.

Starting interactive mode

Run the binary with no arguments:
./c-calc
c-calc checks whether argc == 4. Because no arguments are provided, it falls through to interactive mode and begins prompting immediately.

Session walkthrough

1

First number prompt

c-calc prints the startup message and then asks for the first operand:
This is a simple calculator written in c
Enter your first number: 
Type a number and press Enter. The program reads a double using scanf. If the input cannot be parsed as a number, it prints Invalid input and returns 1 as a fallback value.
2

Operator prompt

After a valid first number is entered, c-calc asks for the operator:
Enter operator: 
Type one of the supported operators (+, -, *, /, %) and press Enter. The program reads a single character. If scanf fails, it prints Invalid input.
3

Second number prompt

c-calc then asks for the second operand:
Enter your second number: 
Type a number and press Enter. The same scanf validation applies as for the first number.
4

Result

Once all three values are collected, c-calc computes and prints the result formatted to four decimal places:
Result: 50.0000

Example session

The following shows a complete interactive session multiplying 10 by 5:
This is a simple calculator written in c
Enter your first number: 10
Enter operator: *
Enter your second number: 5
Result: 50.0000

Error handling

Invalid input — if scanf cannot parse the value you enter as a number or character, the program prints:
Invalid input
The calculation still proceeds using the fallback value 1, which may produce an unexpected result. Re-run the program to start over. Unknown operator — if you enter a character that is not one of the five supported operators, c-calc prints:
Unknown operator
The result is then reported as -1.0000 because the calculate function returns -1 when no case matches. See Supported operators and behavior for the full list.

Build docs developers (and LLMs) love