Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Basic-Calc

A console calculator in C++. Prompts for an operator and two numbers, prints the result to two decimal places, and loops until you decline another calculation.

Learning-exercise code from 2023 — small, single-file, no dependencies.

What it does

  • Four operations: +, -, *, /
  • Fixed two-decimal output (std::setprecision(2))
  • Guards division by zero instead of producing inf
  • Rejects an unknown operator with Invalid operator! and re-prompts
  • Repeats while you answer y / Y

Build and run

The source file is named cpp with no extension — pass it to the compiler explicitly, or rename it to main.cpp first.

g++ -x c++ -o basic-calc cpp
./basic-calc
Enter operator (+, -, *, /): *
Enter two numbers: 7 6
7.00 * 6.00 = 42.00
Do you want to perform another calculation? (y/n): n

Known limits

Input is read with std::cin >> and is not validated — typing a non-number puts the stream into a fail state and the loop spins. Add cin.clear() + cin.ignore() handling if you want it robust.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors