Any C# PRO can help me 3 simple coding?

Discussion in 'C#' started by Zlebronjames, Jun 14, 2006.

  1. Zlebronjames

    Zlebronjames New Member

    Joined:
    Jun 14, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    ^_^The code is very short one that I remember I teacher show me before but I cannot remember. This may be long to read but the code is really simple plz here me Im new to C#. There are 3 steps needing to change the program.

    1)*Never disabling the add grade button* :cool:
    remove the code from the btnAdd_click event handler so that the Add Grade Button is not disabled after entering 10 grades.

    2)*Summing the grades in the ListBox.* :eek:
    modify code in the btnAverage_Click event handler so that inGradeCounter is incremented until it is equal to the number of grades entered. Use lstGrades.Items.Count to determine the number of items in the Listbox. The number returned by the Count property will be zero if there are no grades entered. Use an if selection statement to avoid division by zero and display a message dialog to the user if there are no grades entered when the user clicks the Average button.

    3)*Calcualting the class average* :confused:
    Modify the code in the btnAverage_Click event handler so that dblAverage is computed by using intGradeCounter rather than the Value 10.


    I had the statment in short for some of the main code
    Code:
         static void Main()
         {
            Application.Run( new FrmClassAverage() );
         }
    
         // handles Add Grade Button's Click event
         private void btnAdd_Click(
            object sender, System.EventArgs e )
         {
            // clear previous grades and calculation result
            if ( lblOutput.Text != "" )
            {
               lblOutput.Text = "";
               lstGrades.Items.Clear();
            }
    
            // display grade in ListBox
            lstGrades.Items.Add( Int32.Parse( txtInput.Text ) );
            txtInput.Clear(); // clear grade from TextBox
            txtInput.Focus(); // transfer focus to TextBox
    
            // prohibit users from entering more than 10 grades
            if ( lstGrades.Items.Count == 10 )
            {
               btnAdd.Enabled = false; // disable Add Grade Button
               btnAverage.Focus(); // transfer focus to Average Button
            }
    
         } // end method btnAdd_Click
    
         // handles Average Button's Click event
         private void btnAverage_Click(
            object sender, System.EventArgs e )
         {
            // initialization phase
            int intTotal = 0;
            int intGradeCounter = 0;
            int intGrade = 0;
            double dblAverage = 0;
    
            // sum grades in ListBox
            do
            {
               // read grade from ListBox
               intGrade = ( int )
                  lstGrades.Items[ intGradeCounter ];
               intTotal += intGrade; // add grade to total
               intGradeCounter++; // increment counter
            } while ( intGradeCounter < 10 );
    
            dblAverage = intTotal / 10.0; // calculate average
            lblOutput.Text = String.Format( "{0:F}", dblAverage );
            btnAdd.Enabled = true; // enable Add Grade Button
            txtInput.Focus(); // reset focus to Enter grade: TextBox
    
         } // end method btnAverage_Click
    
      } // end class FrmClassAverage
    }
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Comment out the if below the lines // prohibit users from entering more than 10 grades

    Use lstGrades.Items.Count instead of 10 in while ( intGradeCounter < 10 ); and after that add the if condition.

    Use the variable intGradeCounter intTotal / 10.0; instead of 10

    You cannot ask for the code solution as thats against the TOS of G4EF.

    Thanks
    Shabbir
     
  3. Zlebronjames

    Zlebronjames New Member

    Joined:
    Jun 14, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    May I know how to use lstGrades.Items.Count command? Can show me example?

    I also need to know how the intGradeCounter works to be able to count the variable number?
    Im new to this software so I may need to know more.

    Thanks for your understanding.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Just replace 10 with lstGrades.Items.Count. Just giving the example would mean solving of the problem and thats against G4EF terms.
    By incrementing it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice