问题描述
使用c#和visual studio处理作业。我希望用户输入他们工作的天数以及每天在列表框中显示的工资。但是,薪水需要每天翻倍。因此,第1天他们得到1便士,第2天他们得到2便士,第3天,他们得到4便士等。难以增加2倍,同时仍然保持计数仅上升一天。
我尝试过:
//声明变量
double dblDays;
double dblPay;
int intCounter = 1;
if(Double.TryParse(txtDays.Text,out dblDays))
{
for(intCounter = 1; intCounter< ; = dblDays; intCounter ++)
{
dblPay =(dblDays * .01)* intCounter;
lstDays.Items.Add( 支付日+ intCounter.ToString()+=+ dblPay.ToString(c));
lblTotalPayEarnedTotal.Text = dblPay.ToString(c);
Working on an assignment using c# and visual studio. I want the user to type in how many days they worked and the pay for each day to show in a listbox. However, the pay needs to double each day. So day 1 they get 1 penny, day 2 they get 2 pennies, day 3, they get 4 pennies, etc. Having trouble getting to increase by 2x, while still keeping the count only going up by one day.
What I have tried:
//declare the variables
double dblDays;
double dblPay;
int intCounter=1;
if (Double.TryParse(txtDays.Text, out dblDays))
{
for (intCounter = 1; intCounter <= dblDays; intCounter ++)
{
dblPay = (dblDays*.01) * intCounter;
lstDays.Items.Add("Pay for Day" + intCounter.ToString() + "=" + dblPay.ToString("c"));
lblTotalPayEarnedTotal.Text = dblPay.ToString("c");
推荐答案
这篇关于循环,同时增加2倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!