DEV Community

Mayank Roy
Mayank Roy

Posted on

Day 5: Operators in C++ – Building Blocks of Logic

Understanding Operators in C++

Operators are the backbone of programming in C++, allowing us to perform operations, make decisions, and control the flow of a program. On Day 5 of my C++ journey, I dived deep into the world of operators and uncovered how they act as the tools to manipulate and process data effectively. Here's a summary of what I learned:

Arithmetic Operators
Write a program that calculates the price of tea packs. A user enters the number of tea packs they want, and the price per pack. Apply a 10% tax to the total price and display the final cost.

Image description

Assignment Operators
Create a program where the user inputs the number of tea bags they have. If the number is less than 10, give them 5 extra bags using the += assignment operator. Display the updated total.

Image description

Relational Operators
A tea shop offers a loyalty program. Customers who buy more than 20 cups of tea get a special "Gold" badge, and those who buy 10 to 20 cups get a "Silver" badge. Write a program to display the badge they will receive based on the number of cups they buy.

Image description

Logical Operators
Create a program that checks if a user is eligible for a tea subscription discount. The discount applies if the user is either a student or has purchased more than 15 cups. Ask the user to input their status (student or not) and their cup count. ​​

Image description

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay