User
Pass
2FA
 
 

Intrebare atestat

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database
Author Message1516
In2ition

[Globul de cristal]



Status: Offline
(since 30-04-2018 18:33)
Joined: 28 Aug 2006
Posts: 11769, Topics: 315
Location: Galati

Reputation: 1842.7
Votes: 199

Post Posted: 22-12-2010, 09:43:31 | Translate post to: ... (Click for more languages)

Cum pot sa rescriu codul sursa de mai jos fara functia switch, doar cu if,while,for ?




int x=0, r=2, c=3, tempR=0, tempC=0, temp=0;
bool test;

for (int i=0;i<=2000;i++)
{
test = false;
while (test==false) {
x=rand()%4;
switch (x){
case 0: //check up
if (r-1 >= 0){
tempR = r-1;
tempC = c;
test = true;
}
break;
case 1: //check right
if (c+1 <= 3){
tempR = r;
tempC = c+1;
test = true;
}
break;
case 2:
if (r+1 <= 2){
tempR = r+1;
tempC = c;
test = true;
}
break;
case 3:
if (c-1 >= 0){
tempR = r;
tempC = c-1;
test = true;
}
break;
}
}


We stop looking for monsters under the bed when we realize they're inside of us.

nr913 wrote:
no really, dacã nu era așa țãrancã, și dacã era în bucurești, o luam de nevastã

0 0
  
Back to top
View user's profile Send private message
ion

[prin vacante]



Status: Offline
(since 10-12-2018 10:49)
Joined: 30 Jan 2008
Posts: 7503, Topics: 333
Location: Romania

Reputation: 1770.2
Votes: 191

 
Post Posted: 22-12-2010, 12:34:44 | Translate post to: ... (Click for more languages)

r si c raman neschimbate, nu ar fi trebuit sa ia valorile lui tempR, respectiv tempC la sfarsitul iteratiei lui for ? cred ca poti scrie asa:


Code:
int x=0, r=2, c=3, tempR=0, tempC=0, temp=0;
bool test;

for (int i=0;i<=2000;i++)
{
   test = false;
   while (test==false) {
      x=rand()%4;
      if(x==0){
         tempR = r-1;
         tempC = c;
         test = true;
         }
      if(x==3){
         tempR = r;
         tempC = c-1;      
         test = true;
         }      
   }
}



0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
kEw

[Augh Augh Augh !]



Status: Offline
(since 23-01-2013 17:14)
Joined: 17 Jan 2010
Posts: 37, Topics: 11
Location: data not found...

Reputation: 204.7
Votes: 4

 
Post Posted: 22-12-2010, 21:02:21 | Translate post to: ... (Click for more languages)

ion.mzk wrote:
r si c raman neschimbate, nu ar fi trebuit sa ia valorile lui tempR, respectiv tempC la sfarsitul iteratiei lui for ? cred ca poti scrie asa:


Code:
int x=0, r=2, c=3, tempR=0, tempC=0, temp=0;
bool test;

for (int i=0;i<=2000;i++)
{
   test = false;
   while (test==false) {
      x=rand()%4;
      if(x==0){
         tempR = r-1;
         tempC = c;
         test = true;
         }
      if(x==3){
         tempR = r;
         tempC = c-1;      
         test = true;
         }      
   }
}


Da intr-un final vor lua si valorile respective,dar partea aia din algoritm nu a mai fost postata.


~ Veni, Vidi, Vici ! ~
0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
ion

[prin vacante]



Status: Offline
(since 10-12-2018 10:49)
Joined: 30 Jan 2008
Posts: 7503, Topics: 333
Location: Romania

Reputation: 1770.2
Votes: 191

 
Post Posted: 22-12-2010, 22:19:53 | Translate post to: ... (Click for more languages)

Atunci pui analog if(x==1) , if(x==2) si pentru celelalte 2 cazuri.


0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
kEw

[Augh Augh Augh !]



Status: Offline
(since 23-01-2013 17:14)
Joined: 17 Jan 2010
Posts: 37, Topics: 11
Location: data not found...

Reputation: 204.7
Votes: 4

 
Post Posted: 22-12-2010, 23:11:17 | Translate post to: ... (Click for more languages)

ion.mzk wrote:
Atunci pui analog if(x==1) , if(x==2) si pentru celelalte 2 cazuri.


Ok.Multumim pentru ajutor.


~ Veni, Vidi, Vici ! ~
0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database  


The time now is 03-12-2024, 07:52:12
Copyright info

Based on phpBB ro/com
B

 
 
 







I forgot my password