Session 4: Working with Numbers and Math
Your Name
- 5 minutes read - 916 wordsSession 4: Working with Numbers and Math
Master arithmetic operations, understand operator precedence, and work with different number types to create calculation programs.
🎯 Key Skills You'll Learn:
- Arithmetic operators
- Math functions
- Assignment shortcuts
- Integer vs decimal division
🚀 Session Project:
Compound Interest Calculator
Learning Objectives
- Master arithmetic operations in C++
- Understand operator precedence
- Work with different number types
- Create calculation programs
Warm-up (10 minutes)
Quick Review Exercise: Create a program that asks for two numbers and displays them. Make one an integer and one a decimal number.
New Concept Introduction (30 minutes)
Arithmetic Operators
C++ uses these symbols for math:
|
|
Important: Integer vs Decimal Division
|
|
Operator Precedence (Order of Operations)
C++ follows math rules: PEMDAS/BODMAS
|
|
Useful Math Operations
|
|
Assignment Operators (Shortcuts)
|
|
Hands-on Practice (40 minutes)
Exercise 1: Calculator Upgrade (15 minutes)
|
|
Exercise 2: Temperature Converter (15 minutes)
|
|
Exercise 3: Circle Calculator (10 minutes)
|
|
Challenge/Quiz (10 minutes)
Challenge: Compound Interest Calculator Create a program that calculates compound interest using the formula: Final Amount = Principal × (1 + rate/100)^time
Ask the user for:
- Initial amount (principal)
- Interest rate (as percentage, like 5 for 5%)
- Number of years
Display the final amount and how much interest was earned.
Validation Prompt
🤖 AI Validation Prompt
Copy this prompt and your code to ChatGPT or Claude for instant feedback:
```
I'm learning C++ and just completed Session 4. Here's my solution to the Compound Interest Calculator challenge:
[PASTE YOUR CODE HERE]
The challenge was: Create a program that calculates compound interest using the formula: Final Amount = Principal × (1 + rate/100)^time
Please check if my solution:
1. Uses the correct compound interest formula
2. Handles decimal numbers appropriately
3. Uses the pow() function correctly
4. Displays both final amount and interest earned
5. Has good variable names and clear output
If there are issues, please explain what's wrong and give me a hint to fix it (don't give me the complete solution).
```
What You Learned
- ✅ Arithmetic operators (+, -, *, /, %)
- ✅ Integer vs decimal division
- ✅ Operator precedence and parentheses
- ✅ Assignment shortcuts (+=, -=, etc.)
- ✅ Math functions (sqrt, pow, abs)
Next Session Preview
In Session 5, you’ll learn to work with text and strings, including handling spaces and manipulating text data!