IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

[C#] Probleme de boucle for et random


Sujet :

Windows Forms

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 7
    Points : 5
    Points
    5
    Par défaut [C#] Probleme de boucle for et random
    Bonjour, je suis en train de faire le jeu mastermind et pour ca j'ai besoin de creer un tableau de 5 "cases" dans lequel je met des nombres aléatoire de 1 a 8, le probleme c'est qu'il me met 7 erreurs a la compilations. Je pense que mon code est bon mais je commence a avoir des doutes, le voici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    int[] combi = new int[5];
    Random rnd = new Random();
    for (int c=0; c<5; c++)
    {
        combi[c] = rnd.Next(1, 8);
    }
    J'ai bien tout essayer mais rien y fait, je commence a deseperer (je precise que je suis sous SharpDevelop 1.0.3)

    Merci de votre aide

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    quelles sont les erreurs que tu as ?

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    • (L205) Jeton 'for' non valide dans la déclaration de membres de la classe, structure ou interface(CS1519)
      (L205) Jeton '<' non valide dans la déclaration de membres de la classe, structure ou interface(CS1519)
      (L205) Jeton '++' non valide dans la déclaration de membres de la classe, structure ou interface(CS1519)
      (L207) Erreur de syntaxe, ']' attendu(CS1003)
      (L207) ; attendu(CS1002)
      (L207) Jeton '(' non valide dans la déclaration de membres de la classe, structure ou interface(CS1519)
      (L210) Definition de type ou d'espace de noms, ou de fin de fichier attendue(CS1022)


    Je remet le code avec les lignes qui vont bien

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    L203         int[] combi = new int[5];
    L204         Random rnd = new Random();
    L205         for (int c=0; c<5; c++)
    L206         {
    L207             combi[c] = rnd.Next(1, 8);
    L208         }
    L209     }
    L210 }
    Sachant que le L210, c'est la fin de fichier

    Merci.

  4. #4
    Rédacteur
    Avatar de dev01
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    2 451
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 451
    Points : 6 017
    Points
    6 017
    Par défaut
    Salut

    Montre nous ta classe aparament il manque soit des acolades soit des paratheses quelque part ... Vérifie la totalité de ta syntaxe de la classe .
    - MVP C#
    -Tout problème a une solution, le vrai problème est de trouver la solution .....
    - Linux & mono : l'avenir

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    Bon je met tout mon code lol

    Je soupconne que c'est parce que j'ai foutu mon code un peu n'importe ou mais bon, je debute alors je savais pas ou le mettre.

    J'ai vérifié, pour moi, il manque aucune acolade

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
     
    /*
     * Created by SharpDevelop.
     * User: Thomas
     * Date: 08/01/2005
     * Time: 20:18
     */
    using System;
    using System.Drawing;
    using System.Windows.Forms;
     
    namespace Mastermind
    {
    	/// <summary>
    	/// Description of MainForm.
    	/// </summary>
    	public class MainForm : System.Windows.Forms.Form
    	{
    		private System.Windows.Forms.TextBox o_pion1;
    		private System.Windows.Forms.TextBox o_pion3;
    		private System.Windows.Forms.Button bt_Tester;
    		private System.Windows.Forms.TextBox n_pion4;
    		private System.Windows.Forms.TextBox o_pion4;
    		private System.Windows.Forms.TextBox n_pion5;
    		private System.Windows.Forms.TextBox n_pion1;
    		private System.Windows.Forms.TextBox n_pion2;
    		private System.Windows.Forms.TextBox n_pion3;
    		private System.Windows.Forms.TextBox o_pion2;
    		private System.Windows.Forms.TextBox o_pion5;
    		public MainForm()
    		{
    			//
    			// The InitializeComponent() call is required for Windows Forms designer support.
    			//
    			InitializeComponent();
     
    			//
    			// TODO: Add constructor code after the InitializeComponent() call.
    			//
    		}
     
    		[STAThread]
    		public static void Main(string[] args)
    		{
    			Application.Run(new MainForm());
    		}
     
    		#region Windows Forms Designer generated code
    		/// <summary>
    		/// This method is required for Windows Forms designer support.
    		/// Do not change the method contents inside the source code editor. The Forms designer might
    		/// not be able to load this method if it was changed manually.
    		/// </summary>
    		private void InitializeComponent() {
    			this.o_pion5 = new System.Windows.Forms.TextBox();
    			this.o_pion2 = new System.Windows.Forms.TextBox();
    			this.n_pion3 = new System.Windows.Forms.TextBox();
    			this.n_pion2 = new System.Windows.Forms.TextBox();
    			this.n_pion1 = new System.Windows.Forms.TextBox();
    			this.n_pion5 = new System.Windows.Forms.TextBox();
    			this.o_pion4 = new System.Windows.Forms.TextBox();
    			this.n_pion4 = new System.Windows.Forms.TextBox();
    			this.bt_Tester = new System.Windows.Forms.Button();
    			this.o_pion3 = new System.Windows.Forms.TextBox();
    			this.o_pion1 = new System.Windows.Forms.TextBox();
    			this.SuspendLayout();
    			// 
    			// o_pion5
    			// 
    			this.o_pion5.Location = new System.Drawing.Point(130, 40);
    			this.o_pion5.MaxLength = 1;
    			this.o_pion5.Name = "o_pion5";
    			this.o_pion5.ReadOnly = true;
    			this.o_pion5.Size = new System.Drawing.Size(21, 20);
    			this.o_pion5.TabIndex = 9;
    			this.o_pion5.Text = "";
    			this.o_pion5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// o_pion2
    			// 
    			this.o_pion2.Location = new System.Drawing.Point(40, 40);
    			this.o_pion2.MaxLength = 1;
    			this.o_pion2.Name = "o_pion2";
    			this.o_pion2.ReadOnly = true;
    			this.o_pion2.Size = new System.Drawing.Size(21, 20);
    			this.o_pion2.TabIndex = 6;
    			this.o_pion2.Text = "";
    			this.o_pion2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// n_pion3
    			// 
    			this.n_pion3.Location = new System.Drawing.Point(70, 10);
    			this.n_pion3.MaxLength = 1;
    			this.n_pion3.Name = "n_pion3";
    			this.n_pion3.Size = new System.Drawing.Size(21, 20);
    			this.n_pion3.TabIndex = 2;
    			this.n_pion3.Text = "";
    			this.n_pion3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// n_pion2
    			// 
    			this.n_pion2.Location = new System.Drawing.Point(40, 10);
    			this.n_pion2.MaxLength = 1;
    			this.n_pion2.Name = "n_pion2";
    			this.n_pion2.Size = new System.Drawing.Size(21, 20);
    			this.n_pion2.TabIndex = 1;
    			this.n_pion2.Text = "";
    			this.n_pion2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// n_pion1
    			// 
    			this.n_pion1.Location = new System.Drawing.Point(10, 10);
    			this.n_pion1.MaxLength = 1;
    			this.n_pion1.Name = "n_pion1";
    			this.n_pion1.Size = new System.Drawing.Size(21, 20);
    			this.n_pion1.TabIndex = 0;
    			this.n_pion1.Text = "";
    			this.n_pion1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// n_pion5
    			// 
    			this.n_pion5.Location = new System.Drawing.Point(130, 10);
    			this.n_pion5.MaxLength = 1;
    			this.n_pion5.Name = "n_pion5";
    			this.n_pion5.Size = new System.Drawing.Size(21, 20);
    			this.n_pion5.TabIndex = 4;
    			this.n_pion5.Text = "";
    			this.n_pion5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// o_pion4
    			// 
    			this.o_pion4.Location = new System.Drawing.Point(100, 40);
    			this.o_pion4.MaxLength = 1;
    			this.o_pion4.Name = "o_pion4";
    			this.o_pion4.ReadOnly = true;
    			this.o_pion4.Size = new System.Drawing.Size(21, 20);
    			this.o_pion4.TabIndex = 8;
    			this.o_pion4.Text = "";
    			this.o_pion4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// n_pion4
    			// 
    			this.n_pion4.Location = new System.Drawing.Point(100, 10);
    			this.n_pion4.MaxLength = 1;
    			this.n_pion4.Name = "n_pion4";
    			this.n_pion4.Size = new System.Drawing.Size(21, 20);
    			this.n_pion4.TabIndex = 3;
    			this.n_pion4.Text = "";
    			this.n_pion4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// bt_Tester
    			// 
    			this.bt_Tester.Location = new System.Drawing.Point(160, 10);
    			this.bt_Tester.Name = "bt_Tester";
    			this.bt_Tester.Size = new System.Drawing.Size(75, 21);
    			this.bt_Tester.TabIndex = 10;
    			this.bt_Tester.Text = "Tester";
    			// 
    			// o_pion3
    			// 
    			this.o_pion3.Location = new System.Drawing.Point(70, 40);
    			this.o_pion3.MaxLength = 1;
    			this.o_pion3.Name = "o_pion3";
    			this.o_pion3.ReadOnly = true;
    			this.o_pion3.Size = new System.Drawing.Size(21, 20);
    			this.o_pion3.TabIndex = 7;
    			this.o_pion3.Text = "";
    			this.o_pion3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// o_pion1
    			// 
    			this.o_pion1.Location = new System.Drawing.Point(10, 40);
    			this.o_pion1.MaxLength = 1;
    			this.o_pion1.Name = "o_pion1";
    			this.o_pion1.ReadOnly = true;
    			this.o_pion1.Size = new System.Drawing.Size(21, 20);
    			this.o_pion1.TabIndex = 5;
    			this.o_pion1.Text = "";
    			this.o_pion1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
    			// 
    			// fen_Princ
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(244, 75);
    			this.Controls.Add(this.bt_Tester);
    			this.Controls.Add(this.o_pion5);
    			this.Controls.Add(this.o_pion4);
    			this.Controls.Add(this.o_pion3);
    			this.Controls.Add(this.o_pion2);
    			this.Controls.Add(this.o_pion1);
    			this.Controls.Add(this.n_pion5);
    			this.Controls.Add(this.n_pion4);
    			this.Controls.Add(this.n_pion3);
    			this.Controls.Add(this.n_pion2);
    			this.Controls.Add(this.n_pion1);
    			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    			this.MaximizeBox = false;
    			this.Name = "fen_Princ";
    			this.Text = "Yamasteg";
    			this.ResumeLayout(false);
    		}
    		#endregion
     
    		int[] combi = new int[5];
    		Random rnd = new Random();
    		for (int c=0; c<5; c++)
    		{
    			combi[c] = rnd.Next(1, 8);
    		}
    	}
    }

  6. #6
    Rédacteur
    Avatar de dev01
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    2 451
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 451
    Points : 6 017
    Points
    6 017
    Par défaut
    Ton code doit se trouver dans une fonction .

    Exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     
    private void RandomComi()
    {
          int[] combi = new int[5];
          Random rnd = new Random();
          for (int c=0; c<5; c++)
          {
             combi[c] = rnd.Next(1, 8);
          } 
    }
    Après du fais appel à cette fonction quand tu en as besoin.

    Si tu es débutant je te conseil d'aller faire un tour dans la rubrique tuto de développez.com tu y trouveras de bon cours pour commencer.
    - MVP C#
    -Tout problème a une solution, le vrai problème est de trouver la solution .....
    - Linux & mono : l'avenir

  7. #7
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    ahhhhhh, ok merci beaucoup, ben je regarde le cours de RM di Scala, mais bon, on peut pas dire que c'est pour debutant, enfin bon .....

    Merci encore

    PS: donc mes soupcons etaient bien fondées

  8. #8
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Merci de penser au tag Résolu

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Encore un probleme de boucle for
    Par flysurfer dans le forum Flash
    Réponses: 1
    Dernier message: 28/04/2008, 14h44
  2. probleme avec boucle "for"
    Par kentaro dans le forum ActionScript 1 & ActionScript 2
    Réponses: 16
    Dernier message: 30/01/2008, 20h15
  3. probleme de boucle for
    Par afssaLERH dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 30/10/2007, 17h30
  4. Probleme de boucle for
    Par rawkus dans le forum Flash
    Réponses: 2
    Dernier message: 14/05/2007, 20h15
  5. [Tableaux] Probleme de boucle for
    Par keumlebarbare dans le forum Langage
    Réponses: 12
    Dernier message: 20/09/2006, 14h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo