0
0
Cprogramming~15 mins

Loop execution flow - Mini Project: Build & Apply

Choose your learning style9 modes available
Loop Execution Flow in C
📖 Scenario: Imagine you are managing a small store and want to count how many customers enter each day for a week. You will use a loop to simulate counting customers day by day.
🎯 Goal: Build a C program that uses a for loop to count customers entering the store for 7 days and prints the total number of customers at the end.
📋 What You'll Learn
Create an integer variable total_customers initialized to 0
Create a for loop with an integer variable day that runs from 1 to 7
Inside the loop, add the number of customers for each day to total_customers
Print the total number of customers after the loop ends
💡 Why This Matters
🌍 Real World
Counting totals over time is common in stores, websites, or any place where you track daily activity.
💼 Career
Understanding loop execution flow is essential for programming tasks like data processing, automation, and simulations.
Progress0 / 4 steps
1
Create the initial variable to hold total customers
Create an integer variable called total_customers and set it to 0.
C
Need a hint?

Use int total_customers = 0; inside the main function.

2
Set up the loop to count days
Add a for loop with an integer variable day that runs from 1 to 7 inclusive.
C
Need a hint?

Use for (int day = 1; day <= 7; day++) { } to loop through days.

3
Add customers each day inside the loop
Inside the for loop, add 5 customers to total_customers each day using total_customers += 5;.
C
Need a hint?

Use total_customers += 5; inside the loop to add customers.

4
Print the total number of customers
After the for loop, print the value of total_customers using printf with the message: Total customers in 7 days: %d\n.
C
Need a hint?

Use printf("Total customers in 7 days: %d\n", total_customers); after the loop.