0
0
Goprogramming~15 mins

Increment and decrement in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Increment and Decrement in Go
๐Ÿ“– Scenario: Imagine you are managing a small store's inventory. You want to keep track of the number of apples you have. Sometimes you sell an apple, so the count goes down. Sometimes you get new apples delivered, so the count goes up.
๐ŸŽฏ Goal: You will create a program that starts with a certain number of apples, then increases and decreases the count using increment and decrement operations.
๐Ÿ“‹ What You'll Learn
Create a variable to hold the number of apples
Create a variable to hold the number of apples delivered
Use increment and decrement operators to update the apple count
Print the final number of apples
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Keeping track of inventory counts in stores or warehouses often requires adding and subtracting items.
๐Ÿ’ผ Career
Understanding how to update values with increments and decrements is a basic skill for programming tasks like counters, loops, and managing quantities.
Progress0 / 4 steps
1
Create the initial apple count
Create a variable called apples of type int and set it to 10.
Go
Need a hint?

Use apples := 10 to create and set the variable.

2
Add the number of apples delivered
Create a variable called delivery of type int and set it to 5.
Go
Need a hint?

Use delivery := 5 to create and set the variable.

3
Update the apple count using increment and decrement
Increase apples by delivery using the += operator. Then decrease apples by 3 using the -= operator.
Go
Need a hint?

Use apples += delivery to add and apples -= 3 to subtract.

4
Print the final number of apples
Use fmt.Println to print the value of apples.
Go
Need a hint?

Use fmt.Println(apples) to show the final count.