Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Karel Adds Items Karel needs to swap some items he finds at the bottom of different pits. Karel starts on the east - most tile,
Karel Adds Items
Karel needs to swap some items he finds at the bottom of different pits. Karel starts on the eastmost tile, facing west, on the top row of the field. Beneath him are several pits, of various depths depth is at least one tile He should go to the bottom of each pit and deposit a number of additional items ie add a number of items to the ones already there Any column can contain a pit, including the first and last one. He needs to end up at the end of the top row our path is always on the top row He starts with an infinite number of items in his bag.
What we have not told you yet is how Karel knows how many additional items he should depositt at the bottom of each pit. The way he finds out is by calling the function decide items once he is at the bottom of the pit where there may be some items or not; this doesn't matter We have implemented this decideitems function for you already. You do not have to write it yourself. Instead, you should just call it at the right time ie when you are at the bottom of the pit and it will work. The function prototype of decideitems is given below. It does not have a return value, but has an integer pointer as an argument. The effect of calling the function is that the memory location addressed by this pointer now contains the number of additional items that need to be placed.
void decideitems int value
One of the main goals of this exercise is for you to get exposure to pointers. We therefore would encourage you to try your best to get the code working on your own, even if it takes a while. The related chapter in the textbook is a valuable resource here. Once someone just tells you how to use this function, you have missed out on a valuable learning opportunity.
Write your code in add.c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started