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.
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.
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.
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.
Top comments (0)