Project design
- C course
- Beginner
- Lesson 19/116
- 6 min
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)andprintfadd,subtract,multiply,dividefunctionsiffor a divide-by-zero checkwhileandswitchfor a menu loop
Ready? Let's start.
Project plan
We'll build the calculator piece by piece:
- First the skeleton: write a header with
mainandprintf - Then add
addandsubtractfunctions - Add
multiplyanddividefunctions - Build a menu with
whileandswitch - 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
// Write the calculator skeletonSample solution
#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
int add(int a, ____) { return a + b; }
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 |