Skip to main content

C Programming Day 7: Week 1 Review & Mini Project - Building a Calculator

(Learn C Programming for Beginners — Day 7)

Congratulations! 🎉 You’ve made it to Day 7 of your 30-Day C Programming Adventure!

You’ve survived the first week. You’ve gone from "What is a compiler?" to writing code that can talk, listen, and do math. That is a huge achievement.

Today is a Milestone Day. We aren't learning new syntax today. Instead, we are going to:
1. Review everything we've learned in Week 1.
2. Build a Mini Project — A fully functional Simple Calculator.
3. Celebrate your progress!


🔄 Week 1 Recap: The Foundation

Let's quickly look back at the tools you've added to your belt:

  • Day 1 & 2: You set up your environment (VS Code + GCC) and wrote the legendary Hello, World!.
  • Day 3: You learned about Variables (int, float, char) — the boxes that hold your data.
  • Day 4: You mastered Input/Output (printf, scanf) — making your programs interactive.
  • Day 5: You unlocked Operators (+, -, %, ==, &&) — the math and logic engines.
  • Day 6: You learned Code Style — writing clean, readable code with comments and proper indentation.

You have all the ingredients. Now, let's cook.


🛠️ Mini Project: The Simple Calculator

We are going to build a program that asks the user for two numbers and then performs addition, subtraction, multiplication, and division on them.

The Plan:

  1. Greet the user.
  2. Ask for two numbers.
  3. Perform calculations (Sum, Difference, Product, Quotient, Remainder).
  4. Display the results neatly.

Step 1: Create the File

Create a new file named day7_calculator.c.

Step 2: Write the Code

Try to write it yourself first! If you get stuck, here is the solution:

/*
    Project: Simple Calculator (Week 1 Milestone)
    Author: [Your Name]
    Date: [Today's Date]
    Description: A program that takes two integers and performs basic arithmetic.
*/

#include <stdio.h>

int main() {
    // 1. Declare Variables
    int num1, num2;
    int sum, diff, prod, rem;
    float quot; // Quotient needs to be a float for decimal precision

    // 2. Input
    printf("====================================\n");
    printf("\tSIMPLE CALCULATOR v1.0\n");
    printf("====================================\n\n");

    printf("Enter the first number: ");
    scanf("%d", &num1);

    printf("Enter the second number: ");
    scanf("%d", &num2);

    // 3. Calculations
    sum = num1 + num2;
    diff = num1 - num2;
    prod = num1 * num2;

    // Typecasting: We convert one integer to float to get a decimal result
    quot = (float)num1 / num2; 

    rem = num1 % num2;

    // 4. Output
    printf("\n--- Results ---\n");
    printf("Addition:\t%d + %d = %d\n", num1, num2, sum);
    printf("Subtraction:\t%d - %d = %d\n", num1, num2, diff);
    printf("Multiplication:\t%d * %d = %d\n", num1, num2, prod);
    printf("Division:\t%d / %d = %.2f\n", num1, num2, quot);
    printf("Modulus:\t%d %% %d = %d\n", num1, num2, rem); // Note: %% prints a single %

    printf("\nThank you for using the calculator!\n");

    return 0;
}

Step 3: Compile and Run

  • gcc day7_calculator.c -o calculator
  • ./calculator

🧠 Key Concepts in Action

  1. Typecasting: Did you notice (float)num1?

    • If we just did num1 / num2 (e.g., 5 / 2), C would do integer division and give us 2.
    • By putting (float) in front, we force C to treat num1 as a decimal number (5.0), so the result becomes 2.5. This is a pro tip!
  2. Escape Sequences: We used \t to align the text and \n for spacing.

  3. Printing %: To print the actual percent symbol in printf, you have to type it twice: %%.


🚀 Challenge: The "Tip Calculator"

Want to push yourself further? Modify your calculator to be a Tip Calculator.
1. Ask for the Bill Amount (float).
2. Ask for the Tip Percentage (int).
3. Calculate the Tip Amount (bill * percentage / 100).
4. Calculate the Total Bill (bill + tip).
5. Print the receipt.


🔮 What's Next? Week 2 Preview

You've mastered the basics. Next week, we give your programs a brain.

  • Week 2 is all about Control Flow.
  • You'll learn how to make your code make decisions (if/else).
  • You'll learn how to repeat tasks (loops) without writing the same code 100 times.

Get some rest, celebrate your Week 1 victory, and I'll see you on Day 8!

Found this helpful? Clap 👏 and follow to keep up with the adventure!

CProgramming #CodingForBeginners #LearnToCode #Programming #Developer

Comments

Popular posts from this blog

Unlock C Programming in 30 Days

Your 30‑Day C Programming Series Click any day below to jump straight to that lesson (opens in a new tab): Day 0: Unlock C Programming in 30 Days Your ultimate self‑study guide introduction—your roadmap for the entire 30‑day journey. Read Day 0 Day 1: What is Programming & Setting Up Your C Lab Understand programming basics and install GCC + VS Code so you’re ready to code. Read Day 1 Day 2: Write Your First “Hello, World!” Learn the anatomy of a C program and compile & run your very first C code . Read Day 2 Day 3: Variables & Basic Data Types Discover how to store and print integers, floats, and characters in C . Read Day 3 Day 4: Interactive Input with scanf Make your programs listen—read numbers, floats, and chars from the user. Read Day 4

C Programming Day 3: Variables, Data Types & Constants - The "Boxes" of Programming

(Learn C Programming for Beginners — Day 3) Welcome back to your 30-Day C Programming Adventure ! 🚀 Yesterday, you wrote your very first "Hello, World!" program. You felt the power of making the computer speak. Today, we’re going to give your programs a memory. Imagine trying to cook a complex meal without any bowls or containers. You’d have ingredients everywhere! In programming, variables are those containers. They hold your data so you can use, change, and display it. Today, we unlock the power of Variables , Data Types , and Constants . By the end of this post, you'll be able to write programs that can store and manipulate information, not just print static text. 🎯 Goals for Today Understand Variables — What they are and how to create them. Master Data Types — Integers, floats, characters, and more. Learn Constants — Values that never change. Write Code — Create a program that stores and prints different types of data. 📦 What is a Varia...

C Programming Day 4: Input/Output - Talking to Your Computer

(Learn C Programming for Beginners — Day 4) Welcome to Day 4 of your 30-Day C Programming Adventure ! 🚀 So far, our programs have been a bit... quiet. We've told the computer what to store (variables) and what to show us ( printf ), but we haven't let the user say anything back. It's been a one-way conversation. Today, that changes. We are going to make your programs interactive . By the end of this post, you'll be able to write programs that ask questions, listen for answers, and respond accordingly. We're diving deep into printf (Output) and its best friend, scanf (Input). 🎯 Goals for Today Master printf — Learn how to format output beautifully. Unlock scanf — Learn how to take input from the user. Handle Common Pitfalls — Avoid the dreaded "skipped input" bug. Build an Interactive Program — Create a " Age Calculator " that talks to you. 📢 The Art of Speaking: printf Revisited You've used printf to print...