www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Problem with a for loop in a switch case?

reply Hytak <Hytak_member pathlink.com> writes:
Hi, I am starting D (I love it so much!), and I'm getting better day by day (I
said better, not good ;) ) but I have a little problem.

To practice, I decided to translate little programs I did in C++ when I was
beginning my C++, but there is one problem I'm not able to find/fix (I fixed a
lot ...).

Here it is:
It's a kind of emulation of a card game, and it's really not complicated. I have
few functions that ask number to the player, and after it compare with a
randomly choosed number. (That's approximatively that.) But in my main(), i have
this code:

int main()
{
[...]

PresenterJeu();

stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
mode = stdin.readLine();

switch(mode)
{
case "1":      		
for (int i = 0; i < 15; i++)
{
pc.RandomSouris();
stdout.writef("\nTour ", toString(i+1));
stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
stdout.writef("Joueur 1: ", toString(joueur.GetTotal));                
stdout.writef("Joueur 2: ", toString(adv.GetTotal));                 
stdout.writeLine("");
}             
break;

[...]
}

but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, but the
window doesn't freeze... but I can't write anything , and the crusor is
clignoting... nobody know how to fix this mistake? It's probably a little thing
really easy, but so... (lol... that's the last problem of my apps and it happens
at the very last time)

Is this code correct, and the problems come from another part of my code that I
did not translated well?
Sep 26 2004
next sibling parent reply Regan Heath <regan netwin.co.nz> writes:
On Mon, 27 Sep 2004 00:24:58 +0000 (UTC), Hytak 
<Hytak_member pathlink.com> wrote:
 Hi, I am starting D (I love it so much!), and I'm getting better day by 
 day (I
 said better, not good ;) ) but I have a little problem.

 To practice, I decided to translate little programs I did in C++ when I 
 was
 beginning my C++, but there is one problem I'm not able to find/fix (I 
 fixed a
 lot ...).

 Here it is:
 It's a kind of emulation of a card game, and it's really not 
 complicated. I have
 few functions that ask number to the player, and after it compare with a
 randomly choosed number. (That's approximatively that.) But in my 
 main(), i have
 this code:

 int main()
 {
 [...]

 PresenterJeu();

 stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
 mode = stdin.readLine();

 switch(mode)
 {
 case "1":      		
 for (int i = 0; i < 15; i++)
 {
 pc.RandomSouris();
 stdout.writef("\nTour ", toString(i+1));
 stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
 ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
 stdout.writef("Joueur 1: ", toString(joueur.GetTotal));
 stdout.writef("Joueur 2: ", toString(adv.GetTotal));
 stdout.writeLine("");
 }
 break;

 [...]
 }

 but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, 
 but the
 window doesn't freeze... but I can't write anything , and the crusor is
 clignoting... nobody know how to fix this mistake? It's probably a 
 little thing
 really easy, but so... (lol... that's the last problem of my apps and it 
 happens
 at the very last time)

 Is this code correct, and the problems come from another part of my code 
 that I did not translated well?
Did you press <enter> (or <return>) after pressing '1'? Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Sep 26 2004
parent reply Hytak <Hytak_member pathlink.com> writes:
In article <opseymp5e15a2sq9 digitalmars.com>, Regan Heath says...
On Mon, 27 Sep 2004 00:24:58 +0000 (UTC), Hytak 
<Hytak_member pathlink.com> wrote:
 Hi, I am starting D (I love it so much!), and I'm getting better day by 
 day (I
 said better, not good ;) ) but I have a little problem.

 To practice, I decided to translate little programs I did in C++ when I 
 was
 beginning my C++, but there is one problem I'm not able to find/fix (I 
 fixed a
 lot ...).

 Here it is:
 It's a kind of emulation of a card game, and it's really not 
 complicated. I have
 few functions that ask number to the player, and after it compare with a
 randomly choosed number. (That's approximatively that.) But in my 
 main(), i have
 this code:

 int main()
 {
 [...]

 PresenterJeu();

 stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
 mode = stdin.readLine();

 switch(mode)
 {
 case "1":      		
 for (int i = 0; i < 15; i++)
 {
 pc.RandomSouris();
 stdout.writef("\nTour ", toString(i+1));
 stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
 ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
 stdout.writef("Joueur 1: ", toString(joueur.GetTotal));
 stdout.writef("Joueur 2: ", toString(adv.GetTotal));
 stdout.writeLine("");
 }
 break;

 [...]
 }

 but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, 
 but the
 window doesn't freeze... but I can't write anything , and the crusor is
 clignoting... nobody know how to fix this mistake? It's probably a 
 little thing
 really easy, but so... (lol... that's the last problem of my apps and it 
 happens
 at the very last time)

 Is this code correct, and the problems come from another part of my code 
 that I did not translated well?
Did you press <enter> (or <return>) after pressing '1'? Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Who do you think am I? I am not that dump! I pressed enter. But after pressing enter, nothing happened.
Sep 26 2004
next sibling parent J C Calvarese <jcc7 cox.net> writes:
Hytak wrote:

 In article <opseymp5e15a2sq9 digitalmars.com>, Regan Heath says...
 
On Mon, 27 Sep 2004 00:24:58 +0000 (UTC), Hytak 
<Hytak_member pathlink.com> wrote:

Hi, I am starting D (I love it so much!), and I'm getting better day by 
day (I
said better, not good ;) ) but I have a little problem.

To practice, I decided to translate little programs I did in C++ when I 
was
beginning my C++, but there is one problem I'm not able to find/fix (I 
fixed a
lot ...).

Here it is:
It's a kind of emulation of a card game, and it's really not 
complicated. I have
few functions that ask number to the player, and after it compare with a
randomly choosed number. (That's approximatively that.) But in my 
main(), i have
this code:

int main()
{
[...]

PresenterJeu();

stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
mode = stdin.readLine();

switch(mode)
{
case "1":      		
for (int i = 0; i < 15; i++)
{
pc.RandomSouris();
stdout.writef("\nTour ", toString(i+1));
stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
stdout.writef("Joueur 1: ", toString(joueur.GetTotal));
stdout.writef("Joueur 2: ", toString(adv.GetTotal));
stdout.writeLine("");
}
break;

[...]
}

but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, 
but the
window doesn't freeze... but I can't write anything , and the crusor is
clignoting... nobody know how to fix this mistake? It's probably a 
little thing
really easy, but so... (lol... that's the last problem of my apps and it 
happens
at the very last time)

Is this code correct, and the problems come from another part of my code 
that I did not translated well?
Did you press <enter> (or <return>) after pressing '1'? Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Who do you think am I?
I have no idea.
 I am not that dump!
No one accused you of being "dump". If that's the appreciation you show when someone tries to help, don't be surprised if you don't get much help in the future.
 I pressed enter. But after pressing enter, nothing happened.
-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Sep 26 2004
prev sibling parent Regan Heath <regan netwin.co.nz> writes:
On Mon, 27 Sep 2004 00:54:21 +0000 (UTC), Hytak 
<Hytak_member pathlink.com> wrote:
 In article <opseymp5e15a2sq9 digitalmars.com>, Regan Heath says...
 On Mon, 27 Sep 2004 00:24:58 +0000 (UTC), Hytak
 <Hytak_member pathlink.com> wrote:
 Hi, I am starting D (I love it so much!), and I'm getting better day by
 day (I
 said better, not good ;) ) but I have a little problem.

 To practice, I decided to translate little programs I did in C++ when I
 was
 beginning my C++, but there is one problem I'm not able to find/fix (I
 fixed a
 lot ...).

 Here it is:
 It's a kind of emulation of a card game, and it's really not
 complicated. I have
 few functions that ask number to the player, and after it compare with 
 a
 randomly choosed number. (That's approximatively that.) But in my
 main(), i have
 this code:

 int main()
 {
 [...]

 PresenterJeu();

 stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre 
 l'ordinateur\n");
 mode = stdin.readLine();

 switch(mode)
 {
 case "1":      		
 for (int i = 0; i < 15; i++)
 {
 pc.RandomSouris();
 stdout.writef("\nTour ", toString(i+1));
 stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
 ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
 stdout.writef("Joueur 1: ", toString(joueur.GetTotal));
 stdout.writef("Joueur 2: ", toString(adv.GetTotal));
 stdout.writeLine("");
 }
 break;

 [...]
 }

 but when I press 1, it's dooing "kind-of-nothing" ... nothing happens,
 but the
 window doesn't freeze... but I can't write anything , and the crusor is
 clignoting... nobody know how to fix this mistake? It's probably a
 little thing
 really easy, but so... (lol... that's the last problem of my apps and 
 it
 happens
 at the very last time)

 Is this code correct, and the problems come from another part of my 
 code
 that I did not translated well?
Did you press <enter> (or <return>) after pressing '1'? Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Who do you think am I? I am not that dump!
I was simply starting with the simplest answer.. 'occams razor' the 'KISS principle' and all that.. http://www.hyperdictionary.com/dictionary/Occam's+Razor
 I pressed enter. But after pressing enter, nothing happened.
In that case I would place a printf before and after each function/method call at the top level to isolate the execution path it gets stuck in, once you know where it gets stuck go into that method and repeat the process till you find the system call that is locking up. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Sep 26 2004
prev sibling next sibling parent reply Hytak <Hytak_member pathlink.com> writes:
In article <cj7mkp$s8s$1 digitaldaemon.com>, Hytak says...
Hi, I am starting D (I love it so much!), and I'm getting better day by day (I
said better, not good ;) ) but I have a little problem.

To practice, I decided to translate little programs I did in C++ when I was
beginning my C++, but there is one problem I'm not able to find/fix (I fixed a
lot ...).

Here it is:
It's a kind of emulation of a card game, and it's really not complicated. I have
few functions that ask number to the player, and after it compare with a
randomly choosed number. (That's approximatively that.) But in my main(), i have
this code:

int main()
{
[...]

PresenterJeu();

stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
mode = stdin.readLine();

switch(mode)
{
case "1":      		
for (int i = 0; i < 15; i++)
{
pc.RandomSouris();
stdout.writef("\nTour ", toString(i+1));
stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
stdout.writef("Joueur 1: ", toString(joueur.GetTotal));                
stdout.writef("Joueur 2: ", toString(adv.GetTotal));                 
stdout.writeLine("");
}             
break;

[...]
}

but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, but the
window doesn't freeze... but I can't write anything , and the crusor is
clignoting... nobody know how to fix this mistake? It's probably a little thing
really easy, but so... (lol... that's the last problem of my apps and it happens
at the very last time)

Is this code correct, and the problems come from another part of my code that I
did not translated well?
Who do you think am I? Of course I pressed! There isn't the question... if somebody who would have the respect to answer someone as a man to another man, than I am waiting.
Sep 26 2004
parent reply Bastiaan Veelo <Bastiaan.N.Veelo ntnu.no> writes:
Hytak wrote:
 In article <cj7mkp$s8s$1 digitaldaemon.com>, Hytak says...
 
Hi, I am starting D (I love it so much!), and I'm getting better day by day (I
said better, not good ;) ) but I have a little problem.

To practice, I decided to translate little programs I did in C++ when I was
beginning my C++, but there is one problem I'm not able to find/fix (I fixed a
lot ...).

Here it is:
It's a kind of emulation of a card game, and it's really not complicated. I have
few functions that ask number to the player, and after it compare with a
randomly choosed number. (That's approximatively that.) But in my main(), i have
this code:

int main()
{
[...]

PresenterJeu();

stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
mode = stdin.readLine();

switch(mode)
{
case "1":      		
for (int i = 0; i < 15; i++)
{
pc.RandomSouris();
stdout.writef("\nTour ", toString(i+1));
stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
stdout.writef("Joueur 1: ", toString(joueur.GetTotal));                
stdout.writef("Joueur 2: ", toString(adv.GetTotal));                 
stdout.writeLine("");
}             
break;

[...]
}

but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, but the
window doesn't freeze... but I can't write anything , and the crusor is
clignoting... nobody know how to fix this mistake? It's probably a little thing
really easy, but so... (lol... that's the last problem of my apps and it happens
at the very last time)

Is this code correct, and the problems come from another part of my code that I
did not translated well?
Who do you think am I? Of course I pressed! There isn't the question... if somebody who would have the respect to answer someone as a man to another man, than I am waiting.
First of all, this is a pleasant list (like the language) and I have yet to see a disrespectful post that was meant to be disrespectful --- although you are getting close yourself. But let's cool down. I can't see anything wrong with the code you posted. Are you sure that pc.RandomSouris() returns? Else I suggest you write a minimal program with a for-loop in a switch statement, and see if it behaves as you expect it to behave. If it does not, you may have discovered a bug. See you around, Bastiaan.
Sep 26 2004
parent reply Hytak <Hytak_member pathlink.com> writes:
In article <cj7rbu$tua$1 digitaldaemon.com>, Bastiaan Veelo says...
Hytak wrote:
 In article <cj7mkp$s8s$1 digitaldaemon.com>, Hytak says...
 
Hi, I am starting D (I love it so much!), and I'm getting better day by day (I
said better, not good ;) ) but I have a little problem.

To practice, I decided to translate little programs I did in C++ when I was
beginning my C++, but there is one problem I'm not able to find/fix (I fixed a
lot ...).

Here it is:
It's a kind of emulation of a card game, and it's really not complicated. I have
few functions that ask number to the player, and after it compare with a
randomly choosed number. (That's approximatively that.) But in my main(), i have
this code:

int main()
{
[...]

PresenterJeu();

stdout.writeLine("\t (1) Deux joueurs\n" "\t (2) Contre l'ordinateur\n");
mode = stdin.readLine();

switch(mode)
{
case "1":      		
for (int i = 0; i < 15; i++)
{
pc.RandomSouris();
stdout.writef("\nTour ", toString(i+1));
stdout.writef("\nLa souris vaut: ", toString(sourischoisie));
ComparerCartes(adv.DemanderCarte(),joueur.DemanderCarte());
stdout.writef("Joueur 1: ", toString(joueur.GetTotal));                
stdout.writef("Joueur 2: ", toString(adv.GetTotal));                 
stdout.writeLine("");
}             
break;

[...]
}

but when I press 1, it's dooing "kind-of-nothing" ... nothing happens, but the
window doesn't freeze... but I can't write anything , and the crusor is
clignoting... nobody know how to fix this mistake? It's probably a little thing
really easy, but so... (lol... that's the last problem of my apps and it happens
at the very last time)

Is this code correct, and the problems come from another part of my code that I
did not translated well?
Who do you think am I? Of course I pressed! There isn't the question... if somebody who would have the respect to answer someone as a man to another man, than I am waiting.
First of all, this is a pleasant list (like the language) and I have yet to see a disrespectful post that was meant to be disrespectful --- although you are getting close yourself. But let's cool down. I can't see anything wrong with the code you posted. Are you sure that pc.RandomSouris() returns? Else I suggest you write a minimal program with a for-loop in a switch statement, and see if it behaves as you expect it to behave. If it does not, you may have discovered a bug. See you around, Bastiaan.
I'm sorry, I did not wanted to be unrespectful... It is just that when you spend a lot of time to program something, and that someone tells you "Did you pressed enter" it is VERY offensing. My problem was in my RandomSouris(), I found it before coming to check... or maybe it is in ComparerCarte... I will see... but I will rpboably find Thanks. In future post I will try to specify more my problem, for everyone be able to give an answer without telling things that oculd be offesinging for others.
Sep 27 2004
parent Bastiaan Veelo <Bastiaan.N.Veelo ntnu.no> writes:
 In future post I will try to specify more my problem, for everyone be able to
 give an answer without telling things that oculd be offesinging for others.
Don't take it so hard. The finest minds are on this list, and even they can be in a haze for a moment, and benefit from an obvious answer. There was nothing wrong with the code you showed us, so we give obvious suggestions --- there is no other way we can try to help. One suggestion offends you, but an other (no less obvious) suggestion you seem to endorse. No need to be offended. Try not to assume hostility next time :-) Bastiaan.
Sep 28 2004
prev sibling parent "Jaap Geurts" <jaapsen hotmail.com> writes:
Hi

Hytak: Your code (modified a little ) runs fine on my machine.

#import std.stream;

#int main(char[][]args)




















Sep 27 2004