CodeBlanks Logo Icon CodeBlanks

Project design

Design the structure of the calculator project and write the skeleton code.

Project: Calculator

In this 5-lesson project you'll build a calculator. Each lesson adds one piece, and by the final lesson you'll have a complete app.

You'll use:

  • int main(void) and printf
  • add, subtract, multiply, divide functions
  • if for a divide-by-zero check
  • while and switch for a menu loop

Ready? Let's start.

Project plan

We'll build the calculator piece by piece:

  1. First the skeleton: write a header with main and printf
  2. Then add add and subtract functions
  3. Add multiply and divide functions
  4. Build a menu with while and switch
  5. Put everything together

Each lesson will include the previous lesson's code, so you end up with a working app.

Practice Write the first skeleton

Write a C program: #include <stdio.h>, int main(void), and print Calculator with printf.

Starter code

main.c
// Write the calculator skeleton

Sample solution

main.c
#include <stdio.h>

int main(void) {
    printf("Calculator");
    return 0;
}

Expected output

Calculator

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is the correct signature for add?

  • add(int a, int b)
  • int add(a, b)
  • void add(int a, int b)
  • int add(int a, int b) Correct answer

Explanation: int add(int a, int b) takes two ints and returns an int.

2 Second parameter

Question
int add(int a, ____) { return a + b; }
Answer
int add(int a, int b) { return a + b; }

Explanation: In int add(int a, int b) the second parameter is int b.

3 Match the functions

Term Meaning
add Addition
subtract Subtraction
multiply Multiplication
divide Division

All lessons in Beginner