C# visual c注册系统错误无效输入
我们被要求使用visual c制作一个注册程序,我提出了代码,但我认为每当我输入单位数时都会出现错误,它总是提示无效输入,即使我输入了9个以上的单位,因为我们的教授说单位不能小于9。这是我做的代码C# visual c注册系统错误无效输入,c#,system,C#,System,我们被要求使用visual c制作一个注册程序,我提出了代码,但我认为每当我输入单位数时都会出现错误,它总是提示无效输入,即使我输入了9个以上的单位,因为我们的教授说单位不能小于9。这是我做的代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.T
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 MachineProblem2
{
public partial class frmEnrollment : Form
{
public frmEnrollment()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
rdbInstallment.Checked = true;
rdbRegular.Checked = true;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnCompute_Click(object sender, EventArgs e)
{
int units = Convert.ToInt32(txtUnits.Text);
int tuitionfee = 1250;
double miscfee = .15;
int labfee = 750;
//double scholar = 0;
//double fullpayment = 0;
//double installment = .005;
int totalTuition = 0;
double totalMiscFee = 0;
int totalLabFee = 0;
int totalDiscount = 0;
int computeModePayment = 0;
int computeScholarDiscount = 0;
int scholarDiscount = 80;
int fullpaymentDiscount = 5;
double modeOfPayment = 0;
double status = 0;
double convertedDiscount = 0;
double total = 0;
double installment = 0;
if (txtUnits.Text == "")
{
MessageBox.Show("Input a number", "Input", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
if (units < 9)
{
MessageBox.Show("Error Input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUnits.Clear();
txtUnits.Focus();
}
else
totalLabFee = units * labfee;
txtLabFee.Text = totalLabFee.ToString("C");
totalTuition = units * tuitionfee;
txtTuitionFee.Text = totalTuition.ToString("C");
totalMiscFee = totalTuition * miscfee;
txtMiscFee.Text = totalMiscFee.ToString("C");
totalLabFee = units * labfee;
txtLabFee.Text = totalLabFee.ToString("C");
if (rdbFull.Checked)
{
computeModePayment = fullpaymentDiscount;
}
else
computeModePayment = 0;
if (rdbScholar.Checked)
{
computeScholarDiscount = scholarDiscount;
}
else
computeScholarDiscount = 0;
totalDiscount = computeModePayment + computeScholarDiscount;
txtDiscount.Text = totalDiscount.ToString();
if (rdbFull.Checked)
{
modeOfPayment = totalTuition * 0.05;
}
else
modeOfPayment = 0;
if (rdbScholar.Checked)
{
status = totalTuition * .8;
}
else
status = 0;
convertedDiscount = modeOfPayment + status;
// txtConvertedDiscount.Text = convertedDiscount.ToString("C");
if (rdbInstallment.Checked)
{
installment = totalTuition * .005;
total = (totalTuition + totalLabFee + totalMiscFee - convertedDiscount) + installment;
txtTotal.Text = total.ToString("C");
}
else
total = totalTuition + totalLabFee + totalMiscFee - convertedDiscount;
txtTotal.Text = total.ToString("C");
}
private void btnClear_Click(object sender, EventArgs e)
{
txtUnits.Clear();
txtTuitionFee.Clear();
txtMiscFee.Clear();
txtLabFee.Clear();
txtDiscount.Clear();
txtTotal.Clear();
// txtConvertedDiscount.Clear();
txtUnits.Focus();
rdbFull.Checked = false;
rdbInstallment.Checked = false;
rdbRegular.Checked = false;
rdbScholar.Checked = false;
}
private void btnExit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to exit?", "Exit Application",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
}
Close();
}
}
}
这是我们教授的指导,希望你能帮助我
*单位不得小于9
*学费按每单元1250英镑计算
*杂项费用按每台1250美元计算
*实验室费用按每台750美元计算
*学者八折优惠
*全额付款可享受5%的折扣
*分期付款收取0.5%的费用
int units = Convert.ToInt32(txtUnits.Text).Trim();