Select language
Search the Site
Ceebot / Dauphin Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Schoolbooks-->Branches-->Insect attack (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Schoolbooks-->Branches-->Insect attack
#26
wJack (Visitor)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Schoolbooks-->Branches-->Insect attack 16 Years ago Karma: 0  
Hi, i'm italian boy and i ask you any help for the level:
Schoolbooks-->Branches-->Insect attack...

I don't know how can i do this exercise...
I need help for the istruction switch what i can't understand what put in:
switch (-->/*variabiles*/<--){
....
}and i've another question, without switch my program is:

-----Code-----
extern void object::Apportieren1()
{
while(true){
bool m, a, d, w, s;
string casem="m", casea="a", cased="d", casew="w", cases="s";
if(keypushed(casem)){
fire(0.5);
}
else{
if(keypushed(casea)){
turn(10);
}
else{
if(keypushed(cased)){
turn(-10);
}
else{
if(keypushed(casew)){
aim(20);
}
else{
if(keypushed(cases)){
aim(-20);
}
}
}
}
}
}
}
----End code----

Please help me and answer my doubts
Thanks ...
Giacomo
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/30 16:32 By admin.
  The administrator has disabled public write access.
#28
admin (Admin)
Admin
Posts: 3
graphgraph
User Online Now Click here to see the profile of this user
Re:Schoolbooks-->Branches-->Insect attack 16 Years ago Karma: 1  
I don't understand why you want to use a switch statement. Simple if statements are better adapted to this exercise. You could use a switch statement if you have got a variable which contains the code of the key which has been previously pushed by the user. In this case you could use a switch on the content of this variable.

Your program looks quite OK, with the exception of the aim angle. You will probably have to allow for more possibilities than just 20 degrees upward and 20 degrees down. And why do you use the else statements? If the user pushes two keys at the same time, we would like the robot to perform both actions. Like this, you can write a program which is less complicated.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#29
wJack (Visitor)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Re:Schoolbooks-->Branches-->Insect attack 16 Years ago Karma: 0  
Thanks for your reply... i fix my error... but when i start the program, i've see a message :
Code:

variable not Initialized
??? why?? Sorry for my 'easy' question...
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#30
admin (Admin)
Admin
Posts: 3
graphgraph
User Online Now Click here to see the profile of this user
Re:Schoolbooks-->Branches-->Insect attack 16 Years ago Karma: 1  
Hi,

I copied the program of your first post into the exercise, it works. I have even been able to shoot down some insects with it. You get the error message "Variable not initialized" if you try to use a variable where you never put any content. For example if you write:

if(keypushed(cases))
{
...
}

if before you forgot to write:

string cases = "s";
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#31
wJack (Visitor)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Re:Schoolbooks-->Branches-->Insect attack 16 Years ago Karma: 0  
Thankss... Now it's OK... i refine any codes for my final program

Thanks thanks and yet thanks ... hehe..
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/30 22:14 By .
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop