Skip to content

Robo-Synaptic-Vaish/cpp-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is my first C++ project, built while learning the fundamentals of C++. The goal of this project was not only to build a calculator but also to understand variables, functions, switch statements, loops, and references through practical implementation.

🧮 C++ Calculator

📌 Project Name

C++ Calculator

Version: 1.0


📌 What it does

This is a menu-driven calculator built using C++. It performs the following arithmetic operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division

The program continues running until the user chooses to exit.


📌 Concepts Used

  • The entire project is written in C++.
  • Functions are used to avoid writing the same code repeatedly.
  • Two kinds of repetition are demonstrated in this project:
    • Code repetition: Instead of writing the code for taking two numbers inside every switch case, a separate function (TakeTwoNumbers) is created and reused.
    • Program repetition: The calculator keeps running until the user chooses to exit. This is achieved using a while loop.
  • A switch statement is used to perform different operations based on the user's choice.
  • An if statement is used in the division case to prevent division by zero.
  • Variables are initialized before use. Initializing variables avoids unpredictable (garbage) values and makes the program behave reliably.

📌 How to Compile

After making changes to the code, save the file (Ctrl + S) in VS Code.

Open the integrated terminal and run:

g++ src/main.cpp -o calculator.exe

If the command executes without any errors, the program has been compiled successfully.


📌 How to Run

In the terminal, type:

.\calculator.exe

📚 What I Learned

Through this project, I learned:

  • How C++ source code is compiled into an executable (.exe) file.
  • The difference between source code and executable files.
  • How functions help avoid code repetition.
  • How passing variables by reference allows a function to modify the original variables.
  • How switch statements make menu-driven programs easier to write.
  • How while loops allow a program to keep running until a condition becomes false.
  • Why variables should always be initialized before they are used.
  • How to compile and run a C++ program using g++.

👩‍💻 Author

Vaishnavi Singh

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors