我们要求使用visual c#制作一个注册程序,我提出了代码,但我认为每当我输入单位数时它总是提示“无效输入”时出现错误,即使我输入了9个以上的单位,因为我们的教授说单位不得低于9.继承人我所制作的代码
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计算 * misc费用计算为每单位1250 *实验室费用按每单位750计算 *学者80%的折扣 *全额付款5%的折扣 *分期付款0.5%
答案 0 :(得分:0)
尝试
int units = Convert.ToInt32(txtUnits.Text).Trim();