Problème c#

Bonjour,
J'ai un exercice à faire. C'est une sorte de questionnaire de quatres questions à choix multiples. L'utilisateur doit entrer son choix de réponse ( a,b,c,d,e) pour chaque question. Si il entre la bonne réponse, on affiche Bravo, sinon on affiche Attention. À la fin, on calcule le nombre de bonnes réponses et on affiche un message "Le cumulatif est de 75%" si il entre 3 bonnes réponses (chaque réponse vaut 15%). Comment faire pour l'accumulatif ? Je sais pas, merci pour votre aide

3 réponses

  • Votes
  • Date
  • Date décroissante
  1. Bonjour,

    Je ne connaissais donc pas cette partie de la charte!

    Pour ce qui est du problèmes qui nous concerne :

    Je t'ai déjà donné la solution en entier et je pense que tu est en mesure de trouvé la solution à partir du code que je t'ai donné.

    Il suffit simplement de déclarer une variable à 0 et d'incrémenter cette valeur de 25 pour chaque bonne réponse pour obtenir une note sur 100.

    L'opérateur d'incrémentation en C# es le suivant +=

    Bonne chance à toi et bonne fin de journée!
    N!C£-L!F£!!!
    1. Bonjour,

      Voici un exemple simple et non optimisé.
      Il est maintenant facile de faire de la recher pour trouvé comment optimisé ce code.

      Form1.cs

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      
      namespace WindowsFormsApplication1
      {
          public partial class Form1 : Form
          {
              private int result;
      
              public Form1()
              {
                  InitializeComponent();
              }
      
              private void btnValidate_Click(object sender, EventArgs e)
              {
                  result = 0;
      
                  if (rbQ1R1.Checked == true)
                  {
                      result += 25;
                      lblQ1.Text = "Bravo!";
                      lblQ1.Visible = true;
                  }
                  else
                  {
                      lblQ1.Text = "Attention!";
                      lblQ1.Visible = true;
                  }
      
                  if (rbQ2R4.Checked == true)
                  {
                      result += 25;
                      lblQ2.Text = "Bravo!";
                      lblQ2.Visible = true;
                  }
                  else
                  {
                      lblQ2.Text = "Attention!";
                      lblQ2.Visible = true;
                  }
      
                  if (rbQ3R3.Checked == true)
                  {
                      result += 25;
                      lblQ3.Text = "Bravo!";
                      lblQ3.Visible = true;
                  }
                  else
                  {
                      lblQ3.Text = "Attention!";
                      lblQ3.Visible = true;
                  }
      
                  if (rbQ4R2.Checked == true)
                  {
                      result += 25;
                      lblQ4.Text = "Bravo!";
                      lblQ4.Visible = true;
                  }
                  else
                  {
                      lblQ4.Text = "Attention!";
                      lblQ4.Visible = true;
                  }
      
                  MessageBox.Show("Votre résultat est de " + result + "%" );
      
              }
      
              private void Form1_Load(object sender, EventArgs e)
              {
                  lblQ1.Visible = false;
                  lblQ2.Visible = false;
                  lblQ3.Visible = false;
                  lblQ4.Visible = false;
              }
          }
      }


      Form1.Designer.cs

      namespace WindowsFormsApplication1
      {
          partial class Form1
          {
              /// <summary>
              /// Variable nécessaire au concepteur.
              /// </summary>
              private System.ComponentModel.IContainer components = null;
      
              /// <summary>
              /// Nettoyage des ressources utilisées.
              /// </summary>
              /// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
              protected override void Dispose(bool disposing)
              {
                  if (disposing && (components != null))
                  {
                      components.Dispose();
                  }
                  base.Dispose(disposing);
              }
      
              #region Code généré par le Concepteur Windows Form
      
              /// <summary>
              /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
              /// le contenu de cette méthode avec l'éditeur de code.
              /// </summary>
              private void InitializeComponent()
              {
                  this.groupBox1 = new System.Windows.Forms.GroupBox();
                  this.groupBox2 = new System.Windows.Forms.GroupBox();
                  this.groupBox3 = new System.Windows.Forms.GroupBox();
                  this.groupBox4 = new System.Windows.Forms.GroupBox();
                  this.rbQ1R1 = new System.Windows.Forms.RadioButton();
                  this.rbQ1R2 = new System.Windows.Forms.RadioButton();
                  this.rbQ1R3 = new System.Windows.Forms.RadioButton();
                  this.rbQ1R4 = new System.Windows.Forms.RadioButton();
                  this.rbQ2R4 = new System.Windows.Forms.RadioButton();
                  this.rbQ2R3 = new System.Windows.Forms.RadioButton();
                  this.rbQ2R2 = new System.Windows.Forms.RadioButton();
                  this.rbQ2R1 = new System.Windows.Forms.RadioButton();
                  this.rbQ3R4 = new System.Windows.Forms.RadioButton();
                  this.rbQ3R3 = new System.Windows.Forms.RadioButton();
                  this.rbQ3R2 = new System.Windows.Forms.RadioButton();
                  this.rbQ3R1 = new System.Windows.Forms.RadioButton();
                  this.rbQ4R4 = new System.Windows.Forms.RadioButton();
                  this.rbQ4R3 = new System.Windows.Forms.RadioButton();
                  this.rbQ4R2 = new System.Windows.Forms.RadioButton();
                  this.rbQ4R1 = new System.Windows.Forms.RadioButton();
                  this.lblQ1 = new System.Windows.Forms.Label();
                  this.lblQ2 = new System.Windows.Forms.Label();
                  this.lblQ3 = new System.Windows.Forms.Label();
                  this.lblQ4 = new System.Windows.Forms.Label();
                  this.btnValidate = new System.Windows.Forms.Button();
                  this.groupBox1.SuspendLayout();
                  this.groupBox2.SuspendLayout();
                  this.groupBox3.SuspendLayout();
                  this.groupBox4.SuspendLayout();
                  this.SuspendLayout();
                  // 
                  // groupBox1
                  // 
                  this.groupBox1.Controls.Add(this.lblQ1);
                  this.groupBox1.Controls.Add(this.rbQ1R4);
                  this.groupBox1.Controls.Add(this.rbQ1R3);
                  this.groupBox1.Controls.Add(this.rbQ1R2);
                  this.groupBox1.Controls.Add(this.rbQ1R1);
                  this.groupBox1.Location = new System.Drawing.Point(13, 12);
                  this.groupBox1.Name = "groupBox1";
                  this.groupBox1.Size = new System.Drawing.Size(287, 173);
                  this.groupBox1.TabIndex = 0;
                  this.groupBox1.TabStop = false;
                  this.groupBox1.Text = "1) Quel est la plus belle ville du monde?";
                  // 
                  // groupBox2
                  // 
                  this.groupBox2.Controls.Add(this.lblQ3);
                  this.groupBox2.Controls.Add(this.rbQ3R4);
                  this.groupBox2.Controls.Add(this.rbQ3R3);
                  this.groupBox2.Controls.Add(this.rbQ3R2);
                  this.groupBox2.Controls.Add(this.rbQ3R1);
                  this.groupBox2.Location = new System.Drawing.Point(13, 191);
                  this.groupBox2.Name = "groupBox2";
                  this.groupBox2.Size = new System.Drawing.Size(287, 173);
                  this.groupBox2.TabIndex = 1;
                  this.groupBox2.TabStop = false;
                  this.groupBox2.Text = "3) Quelle couleur est la plus belle?";
                  // 
                  // groupBox3
                  // 
                  this.groupBox3.Controls.Add(this.lblQ2);
                  this.groupBox3.Controls.Add(this.rbQ2R4);
                  this.groupBox3.Controls.Add(this.rbQ2R3);
                  this.groupBox3.Controls.Add(this.rbQ2R2);
                  this.groupBox3.Controls.Add(this.rbQ2R1);
                  this.groupBox3.Location = new System.Drawing.Point(306, 12);
                  this.groupBox3.Name = "groupBox3";
                  this.groupBox3.Size = new System.Drawing.Size(287, 173);
                  this.groupBox3.TabIndex = 1;
                  this.groupBox3.TabStop = false;
                  this.groupBox3.Text = "2) Qui est le meilleur programmeur?";
                  // 
                  // groupBox4
                  // 
                  this.groupBox4.Controls.Add(this.lblQ4);
                  this.groupBox4.Controls.Add(this.rbQ4R4);
                  this.groupBox4.Controls.Add(this.rbQ4R3);
                  this.groupBox4.Controls.Add(this.rbQ4R2);
                  this.groupBox4.Controls.Add(this.rbQ4R1);
                  this.groupBox4.Location = new System.Drawing.Point(306, 191);
                  this.groupBox4.Name = "groupBox4";
                  this.groupBox4.Size = new System.Drawing.Size(287, 173);
                  this.groupBox4.TabIndex = 1;
                  this.groupBox4.TabStop = false;
                  this.groupBox4.Text = "4) Quel est le meilleur forum d\'aide?";
                  // 
                  // rbQ1R1
                  // 
                  this.rbQ1R1.AutoSize = true;
                  this.rbQ1R1.Location = new System.Drawing.Point(29, 43);
                  this.rbQ1R1.Name = "rbQ1R1";
                  this.rbQ1R1.Size = new System.Drawing.Size(76, 17);
                  this.rbQ1R1.TabIndex = 0;
                  this.rbQ1R1.TabStop = true;
                  this.rbQ1R1.Text = "Montréal";
                  this.rbQ1R1.UseVisualStyleBackColor = true;
                  // 
                  // rbQ1R2
                  // 
                  this.rbQ1R2.AutoSize = true;
                  this.rbQ1R2.Location = new System.Drawing.Point(29, 66);
                  this.rbQ1R2.Name = "rbQ1R2";
                  this.rbQ1R2.Size = new System.Drawing.Size(77, 17);
                  this.rbQ1R2.TabIndex = 1;
                  this.rbQ1R2.TabStop = true;
                  this.rbQ1R2.Text = "New York";
                  this.rbQ1R2.UseVisualStyleBackColor = true;
                  // 
                  // rbQ1R3
                  // 
                  this.rbQ1R3.AutoSize = true;
                  this.rbQ1R3.Location = new System.Drawing.Point(29, 89);
                  this.rbQ1R3.Name = "rbQ1R3";
                  this.rbQ1R3.Size = new System.Drawing.Size(53, 17);
                  this.rbQ1R3.TabIndex = 2;
                  this.rbQ1R3.TabStop = true;
                  this.rbQ1R3.Text = "Paris";
                  this.rbQ1R3.UseVisualStyleBackColor = true;
                  // 
                  // rbQ1R4
                  // 
                  this.rbQ1R4.AutoSize = true;
                  this.rbQ1R4.Location = new System.Drawing.Point(29, 112);
                  this.rbQ1R4.Name = "rbQ1R4";
                  this.rbQ1R4.Size = new System.Drawing.Size(64, 17);
                  this.rbQ1R4.TabIndex = 3;
                  this.rbQ1R4.TabStop = true;
                  this.rbQ1R4.Text = "Londre";
                  this.rbQ1R4.UseVisualStyleBackColor = true;
                  // 
                  // rbQ2R4
                  // 
                  this.rbQ2R4.AutoSize = true;
                  this.rbQ2R4.Location = new System.Drawing.Point(30, 112);
                  this.rbQ2R4.Name = "rbQ2R4";
                  this.rbQ2R4.Size = new System.Drawing.Size(57, 17);
                  this.rbQ2R4.TabIndex = 7;
                  this.rbQ2R4.TabStop = true;
                  this.rbQ2R4.Text = "Jesus";
                  this.rbQ2R4.UseVisualStyleBackColor = true;
                  // 
                  // rbQ2R3
                  // 
                  this.rbQ2R3.AutoSize = true;
                  this.rbQ2R3.Location = new System.Drawing.Point(30, 89);
                  this.rbQ2R3.Name = "rbQ2R3";
                  this.rbQ2R3.Size = new System.Drawing.Size(65, 17);
                  this.rbQ2R3.TabIndex = 6;
                  this.rbQ2R3.TabStop = true;
                  this.rbQ2R3.Text = "Jaques";
                  this.rbQ2R3.UseVisualStyleBackColor = true;
                  // 
                  // rbQ2R2
                  // 
                  this.rbQ2R2.AutoSize = true;
                  this.rbQ2R2.Location = new System.Drawing.Point(30, 66);
                  this.rbQ2R2.Name = "rbQ2R2";
                  this.rbQ2R2.Size = new System.Drawing.Size(52, 17);
                  this.rbQ2R2.TabIndex = 5;
                  this.rbQ2R2.TabStop = true;
                  this.rbQ2R2.Text = "Jean";
                  this.rbQ2R2.UseVisualStyleBackColor = true;
                  // 
                  // rbQ2R1
                  // 
                  this.rbQ2R1.AutoSize = true;
                  this.rbQ2R1.Location = new System.Drawing.Point(30, 43);
                  this.rbQ2R1.Name = "rbQ2R1";
                  this.rbQ2R1.Size = new System.Drawing.Size(59, 17);
                  this.rbQ2R1.TabIndex = 4;
                  this.rbQ2R1.TabStop = true;
                  this.rbQ2R1.Text = "Pierre";
                  this.rbQ2R1.UseVisualStyleBackColor = true;
                  // 
                  // rbQ3R4
                  // 
                  this.rbQ3R4.AutoSize = true;
                  this.rbQ3R4.Location = new System.Drawing.Point(29, 112);
                  this.rbQ3R4.Name = "rbQ3R4";
                  this.rbQ3R4.Size = new System.Drawing.Size(47, 17);
                  this.rbQ3R4.TabIndex = 7;
                  this.rbQ3R4.TabStop = true;
                  this.rbQ3R4.Text = "Noir";
                  this.rbQ3R4.UseVisualStyleBackColor = true;
                  // 
                  // rbQ3R3
                  // 
                  this.rbQ3R3.AutoSize = true;
                  this.rbQ3R3.Location = new System.Drawing.Point(29, 89);
                  this.rbQ3R3.Name = "rbQ3R3";
                  this.rbQ3R3.Size = new System.Drawing.Size(61, 17);
                  this.rbQ3R3.TabIndex = 6;
                  this.rbQ3R3.TabStop = true;
                  this.rbQ3R3.Text = "Rouge";
                  this.rbQ3R3.UseVisualStyleBackColor = true;
                  // 
                  // rbQ3R2
                  // 
                  this.rbQ3R2.AutoSize = true;
                  this.rbQ3R2.Location = new System.Drawing.Point(29, 66);
                  this.rbQ3R2.Name = "rbQ3R2";
                  this.rbQ3R2.Size = new System.Drawing.Size(55, 17);
                  this.rbQ3R2.TabIndex = 5;
                  this.rbQ3R2.TabStop = true;
                  this.rbQ3R2.Text = "Blanc";
                  this.rbQ3R2.UseVisualStyleBackColor = true;
                  // 
                  // rbQ3R1
                  // 
                  this.rbQ3R1.AutoSize = true;
                  this.rbQ3R1.Location = new System.Drawing.Point(29, 43);
                  this.rbQ3R1.Name = "rbQ3R1";
                  this.rbQ3R1.Size = new System.Drawing.Size(49, 17);
                  this.rbQ3R1.TabIndex = 4;
                  this.rbQ3R1.TabStop = true;
                  this.rbQ3R1.Text = "Bleu";
                  this.rbQ3R1.UseVisualStyleBackColor = true;
                  // 
                  // rbQ4R4
                  // 
                  this.rbQ4R4.AutoSize = true;
                  this.rbQ4R4.Location = new System.Drawing.Point(30, 112);
                  this.rbQ4R4.Name = "rbQ4R4";
                  this.rbQ4R4.Size = new System.Drawing.Size(64, 17);
                  this.rbQ4R4.TabIndex = 7;
                  this.rbQ4R4.TabStop = true;
                  this.rbQ4R4.Text = "Google";
                  this.rbQ4R4.UseVisualStyleBackColor = true;
                  // 
                  // rbQ4R3
                  // 
                  this.rbQ4R3.AutoSize = true;
                  this.rbQ4R3.Location = new System.Drawing.Point(30, 89);
                  this.rbQ4R3.Name = "rbQ4R3";
                  this.rbQ4R3.Size = new System.Drawing.Size(79, 17);
                  this.rbQ4R3.TabIndex = 6;
                  this.rbQ4R3.TabStop = true;
                  this.rbQ4R3.Text = "Facebook";
                  this.rbQ4R3.UseVisualStyleBackColor = true;
                  // 
                  // rbQ4R2
                  // 
                  this.rbQ4R2.AutoSize = true;
                  this.rbQ4R2.Location = new System.Drawing.Point(30, 66);
                  this.rbQ4R2.Name = "rbQ4R2";
                  this.rbQ4R2.Size = new System.Drawing.Size(49, 17);
                  this.rbQ4R2.TabIndex = 5;
                  this.rbQ4R2.TabStop = true;
                  this.rbQ4R2.Text = "CCM";
                  this.rbQ4R2.UseVisualStyleBackColor = true;
                  // 
                  // rbQ4R1
                  // 
                  this.rbQ4R1.AutoSize = true;
                  this.rbQ4R1.Location = new System.Drawing.Point(30, 43);
                  this.rbQ4R1.Name = "rbQ4R1";
                  this.rbQ4R1.Size = new System.Drawing.Size(57, 17);
                  this.rbQ4R1.TabIndex = 4;
                  this.rbQ4R1.TabStop = true;
                  this.rbQ4R1.Text = "Stack";
                  this.rbQ4R1.UseVisualStyleBackColor = true;
                  // 
                  // lblQ1
                  // 
                  this.lblQ1.AutoSize = true;
                  this.lblQ1.Location = new System.Drawing.Point(26, 141);
                  this.lblQ1.Name = "lblQ1";
                  this.lblQ1.Size = new System.Drawing.Size(45, 13);
                  this.lblQ1.TabIndex = 4;
                  this.lblQ1.Text = "{msg}";
                  // 
                  // lblQ2
                  // 
                  this.lblQ2.AutoSize = true;
                  this.lblQ2.Location = new System.Drawing.Point(27, 141);
                  this.lblQ2.Name = "lblQ2";
                  this.lblQ2.Size = new System.Drawing.Size(45, 13);
                  this.lblQ2.TabIndex = 8;
                  this.lblQ2.Text = "{msg}";
                  // 
                  // lblQ3
                  // 
                  this.lblQ3.AutoSize = true;
                  this.lblQ3.Location = new System.Drawing.Point(26, 144);
                  this.lblQ3.Name = "lblQ3";
                  this.lblQ3.Size = new System.Drawing.Size(45, 13);
                  this.lblQ3.TabIndex = 8;
                  this.lblQ3.Text = "{msg}";
                  // 
                  // lblQ4
                  // 
                  this.lblQ4.AutoSize = true;
                  this.lblQ4.Location = new System.Drawing.Point(27, 144);
                  this.lblQ4.Name = "lblQ4";
                  this.lblQ4.Size = new System.Drawing.Size(45, 13);
                  this.lblQ4.TabIndex = 9;
                  this.lblQ4.Text = "{msg}";
                  // 
                  // btnValidate
                  // 
                  this.btnValidate.Location = new System.Drawing.Point(13, 370);
                  this.btnValidate.Name = "btnValidate";
                  this.btnValidate.Size = new System.Drawing.Size(579, 38);
                  this.btnValidate.TabIndex = 2;
                  this.btnValidate.Text = "Valider";
                  this.btnValidate.UseVisualStyleBackColor = true;
                  this.btnValidate.Click += new System.EventHandler(this.btnValidate_Click);
                  // 
                  // Form1
                  // 
                  this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 13F);
                  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                  this.ClientSize = new System.Drawing.Size(604, 420);
                  this.Controls.Add(this.btnValidate);
                  this.Controls.Add(this.groupBox4);
                  this.Controls.Add(this.groupBox3);
                  this.Controls.Add(this.groupBox2);
                  this.Controls.Add(this.groupBox1);
                  this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.groupBox1.ResumeLayout(false);
                  this.groupBox1.PerformLayout();
                  this.groupBox2.ResumeLayout(false);
                  this.groupBox2.PerformLayout();
                  this.groupBox3.ResumeLayout(false);
                  this.groupBox3.PerformLayout();
                  this.groupBox4.ResumeLayout(false);
                  this.groupBox4.PerformLayout();
                  this.ResumeLayout(false);
      
              }
      
              #endregion
      
              private System.Windows.Forms.GroupBox groupBox1;
              private System.Windows.Forms.GroupBox groupBox2;
              private System.Windows.Forms.GroupBox groupBox3;
              private System.Windows.Forms.GroupBox groupBox4;
              private System.Windows.Forms.Label lblQ1;
              private System.Windows.Forms.RadioButton rbQ1R4;
              private System.Windows.Forms.RadioButton rbQ1R3;
              private System.Windows.Forms.RadioButton rbQ1R2;
              private System.Windows.Forms.RadioButton rbQ1R1;
              private System.Windows.Forms.Label lblQ3;
              private System.Windows.Forms.RadioButton rbQ3R4;
              private System.Windows.Forms.RadioButton rbQ3R3;
              private System.Windows.Forms.RadioButton rbQ3R2;
              private System.Windows.Forms.RadioButton rbQ3R1;
              private System.Windows.Forms.Label lblQ2;
              private System.Windows.Forms.RadioButton rbQ2R4;
              private System.Windows.Forms.RadioButton rbQ2R3;
              private System.Windows.Forms.RadioButton rbQ2R2;
              private System.Windows.Forms.RadioButton rbQ2R1;
              private System.Windows.Forms.Label lblQ4;
              private System.Windows.Forms.RadioButton rbQ4R4;
              private System.Windows.Forms.RadioButton rbQ4R3;
              private System.Windows.Forms.RadioButton rbQ4R2;
              private System.Windows.Forms.RadioButton rbQ4R1;
              private System.Windows.Forms.Button btnValidate;
          }
      }
      


      1. Je vous ai envoyé un message privé pour m'aider, pourriez-vous répondre svp ? Merci