(N) Change¶
Goal: I will take an even closer look at the behavior of integers in C++. I will learn to divide integers use remainders.
Instructions: In the previous exercises you were provided with a ready-made code template and a project file in Git repository. You will not receive a ready code template in all of the exercises on this course. Instead, you should also be able to create a new project in Qt Creator. (Instructions for this can be found from the earlier section 3.3 Qt Creator programming environment, from the point How to use Qt Creator on virtual desktop, from step 4 on.)
In this assignment, you will create the project by yourself.
You need to save the project in the directory with
exactly the correct name in order to
allow the automatic evaluation system to find it when you submit
your solution to the course platform.
Save your project in the
directory student/01/change located in the data repository.
Please note that if you start by creating the project in Qt Creator
under the name change, Qt Creator will save the project
files in a directory called change defined in
the window Project Location.
This means you won’t have to create a separate directory called
change under the directory student/01.
Later on, the first paragraph of the assignment will tell you whether to use a template or create the project yourself, and what the directory should be called.
Assignment: Create a program that asks how much purchases cost and the amount of paid money and then prints the amount of change. To simplify the program, only 1, 2, 5 and 10 euros are offered as change. It is assumed that the paid amount is always euros, i.e. no cents are paid besides euros.
The program should work like the examples below:
Purchase price: 12
Paid amount of money: 50
Offer change:
3 ten-euro notes
1 five-euro notes
1 two-euro coins
1 one-euro coins
Purchase price: 43
Paid amount of money: 50
Offer change:
1 five-euro notes
1 two-euro coins
Purchase price: 12
Paid amount of money: 12
No change
Purchase price: 12
Paid amount of money: 11
No change
Tips for completing the assignment:
Recall how integer division works.
Recall which operator gives the reminder of a integer division.
We have not yet considered functions, and they are not required in this exercise, but you can still consider (without writing code), how you could solve the problem with a function.
A+ presents the exercise submission form here.