Friday, 13 September 2013

Input string is not in correct format - C#

Input string is not in correct format - C#

I've written another GUI like this one that works fine, but this one is
not working properly. Throughout the many other questions I have looked
through on StackOverflow, I didn't see one similar to my issue. Can you
help me, please and thanks? :)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestsInteractiveGUI
{
public partial class averageTestScoreCalculator : Form
{
// Begin the form
public averageTestScoreCalculator()
{
InitializeComponent();
}
// Textbox 1
private void testScoreTextBox1_TextChanged(object sender,
EventArgs e)
{
// Declare the variables
string scoreTB1;
// Have the user enter the test score for Test Score 1
scoreTB1 = testScoreTextBox1.Text;
}
// Textbox 2
private void testScoreTextBox2_TextChanged(object sender,
EventArgs e)
{
// Declare the variables
string scoreTB2;
// Have the user enter the test score for Test Score 2
scoreTB2 = testScoreTextBox2.Text;
}
// Textbox 3
private void testScoreTextBox3_TextChanged(object sender,
EventArgs e)
{
// Declare the variables
string scoreTB3;
// Have the user enter the test score for Test Score 3
scoreTB3 = testScoreTextBox3.Text;
}
// Textbox 4
private void testScoreTextBox4_TextChanged(object sender,
EventArgs e)
{
// Declare the variables
string scoreTB4;
// Have the user enter the test score for Test Score 4
scoreTB4 = testScoreTextBox4.Text;
}
// Textbox 5
private void testScoreTextBox5_TextChanged(object sender,
EventArgs e)
{
// Declare the variables
string scoreTB5;
// Have the user enter the test score for Test Score 5
scoreTB5 = testScoreTextBox5.Text;
}
// Button
private void calculateTestScoresButton_Click(object sender,
EventArgs e)
{
// Declare the variables
const int NUMBER_OF_TESTS = 5;
int scoreTB1Int = Convert.ToInt32(testScoreTextBox1.Text);
int scoreTB2Int = Convert.ToInt32(testScoreTextBox2.Text);
int scoreTB3Int = Convert.ToInt32(testScoreTextBox3.Text);
int scoreTB4Int = Convert.ToInt32(testScoreTextBox4.Text);
int scoreTB5Int = Convert.ToInt32(testScoreTextBox5.Text);
// Declare variables to hold results and calculate the average
test score
double averageScore = (scoreTB1Int + scoreTB2Int + scoreTB3Int
+ scoreTB4Int + scoreTB5Int) / NUMBER_OF_TESTS;
// Enable and display the results
resultLabel.Enabled = true;
resultLabel.Visible = true;
resultLabel.Text = string.Format("The average test score
{0n2}%", averageScore);
}
// Result label
private void resultLabel_Click(object sender, EventArgs e)
{
}
}
}

No comments:

Post a Comment