|
// Beeper transport program. #include <karel.h> using namespace std; int main() { TurnOn(); Move(); Move(); PickBeeper(); Move(); TurnLeft(); Move(); Move(); PutBeeper(); Move(); TurnOff(); } |
Lines that start with // are comments to be read by humans.
The #include line tells the compiler, the program that translates the program to the left into a form that can be executed on the computer, that we are going to be using Karel instructions. The using namespace std; statement tells the compiler to enable the standard namespace. For the time being, just accept that we will always have one occurrence of this statement at the beginning of a program. The int main() and left curly brace ({) are used to package the Karel instructions. Everything up to the terminating right curly brace (}) is considered to be part of the Karel program. Note that instruction statements are terminated by semicolons (;).
|
Start of task End of task
#include <karel.h> using namespace std; int main() { Move(); PickBeeber(); TurnLeft() PutBeeper(); Move; } } |
When you first write a robot program, chances are that it will contain
some errors. There are four types of programming errors:
|