C# 控制台应用程序,应用程序冻结无错误
好吧,现在我自己还不熟悉编程,而且学习速度很慢。目前,我正在学习编程课程,以帮助更好地理解编程。我遇到了一个困扰我的问题 现在,虽然我可以用不同于我所提供的方式和方式完成任务。我的问题是,为什么会发生这种情况?我没有收到任何错误,无论发生什么,唯一发生的事情是在输入之后,控制台出现问题。我想知道我做错了什么C# 控制台应用程序,应用程序冻结无错误,c#,console,C#,Console,好吧,现在我自己还不熟悉编程,而且学习速度很慢。目前,我正在学习编程课程,以帮助更好地理解编程。我遇到了一个困扰我的问题 现在,虽然我可以用不同于我所提供的方式和方式完成任务。我的问题是,为什么会发生这种情况?我没有收到任何错误,无论发生什么,唯一发生的事情是在输入之后,控制台出现问题。我想知道我做错了什么 static void Main(string[] args) { double[] Population = new double[6]; string[] Years
static void Main(string[] args)
{
double[] Population = new double[6];
string[] Years = { "2", "3", "4", "5", "6", "7" };
double GrowthPercentage = 0.0;
double MathPercentage = 0.0000;
double ActualGrowth = 0.0;
int WhileCounter = 0;
//Ask user for Population of Roarkville
Console.WriteLine("Enter the Population of RoarkVille: ");
//Read Population and store
Population[0] = Convert.ToDouble(Console.ReadLine());
//Ask user for Growth percentage
Console.WriteLine("Enter the Growth percentage ");
//Read Growth Percentage
GrowthPercentage = Convert.ToDouble(Console.ReadLine());
//Calculation of Growth Percentage: Growth Percentage/100 = Math Percentage
MathPercentage = GrowthPercentage / 100;
//ActualGrowth = Population * Math Percentage
//Population2 = ActualGrowth + Population
while (WhileCounter < 5)
{
ActualGrowth = Population[WhileCounter] + MathPercentage;
WhileCounter++;
Population[WhileCounter] = ActualGrowth + Population[WhileCounter--];
}
for (int i = 0; i < Population.Length; i++)
{
Console.WriteLine("Population of 201{0:d}", Years[i]);
Console.WriteLine(Population[i]);
}
//Display 2012 Population
//Display 2013 Population
//Display 2014 Population
//Display 2015 Population
//Display 2016 Population
//Display 2017 Population
Console.ReadLine();
}
static void Main(字符串[]args)
{
双[]人口=新的双[6];
字符串[]年={“2”、“3”、“4”、“5”、“6”、“7”};
双增长百分比=0.0;
双倍百分比=0.0000;
双实际增长率=0.0;
int WhileCounter=0;
//向用户询问罗克维尔的人口
Console.WriteLine(“输入罗克维尔的人口:”);
//读取人口和存储
填充[0]=Convert.ToDouble(Console.ReadLine());
//询问用户增长百分比
Console.WriteLine(“输入增长百分比”);
//读取增长百分比
GrowthPercentage=Convert.ToDouble(Console.ReadLine());
//增长百分比的计算:增长百分比/100=数学百分比
MathPercentage=增长百分比/100;
//实际增长=人口*数学百分比
//人口2=实际增长+人口
while(WhileCounter<5)
{
实际增长=人口[WhileCounter]+数学百分比;
WhileCounter++;
人口[WhileCounter]=实际增长+人口[WhileCounter--];
}
for(int i=0;i
就循环而言,WhileCounter
的值永远不会改变。在循环体中,递增WhileCounter
并立即递减,因此条件WhileCounter<5
始终为真
你还不如写信
int WhileCounter = 0;
while(WhileCounter < 5)
{
WhileCounter += 1; // WhileCounter == 1
WhileCounter -= 1; // WhileCounter == 0
}
// aint never gunna happen
int WhileCounter=0;
while(WhileCounter<5)
{
WhileCounter+=1;//WhileCounter==1
WhileCounter-=1;//WhileCounter==0
}
//从来没有发生过吗
就循环而言,WhileCounter
的值永远不会改变。在循环体中,递增WhileCounter
并立即递减,因此条件WhileCounter<5
始终为真
你还不如写信
int WhileCounter = 0;
while(WhileCounter < 5)
{
WhileCounter += 1; // WhileCounter == 1
WhileCounter -= 1; // WhileCounter == 0
}
// aint never gunna happen
int WhileCounter=0;
while(WhileCounter<5)
{
WhileCounter+=1;//WhileCounter==1
WhileCounter-=1;//WhileCounter==0
}
//从来没有发生过吗
您应该仔细阅读以下运算符并了解它们的实际功能:
您应该仔细阅读以下运算符并了解它们的实际功能:
运算符更改变量的实际值,因此
计数器+
会将变量增加1
运算符也执行相同的操作,这不是您希望在该行中执行的操作
Population[WhileCounter] = ActualGrowth + Population[WhileCounter--];
相反,使用WhileCounter-1
,如下所示
Population[WhileCounter] = ActualGrowth + Population[WhileCounter - 1];
++运算符更改变量的实际值,因此
WhileCounter++
将变量增加1
运算符也执行相同的操作,这不是您希望在该行中执行的操作
Population[WhileCounter] = ActualGrowth + Population[WhileCounter--];
相反,使用WhileCounter-1
,如下所示
Population[WhileCounter] = ActualGrowth + Population[WhileCounter - 1];
因此,当您使用以下代码输入增长百分比时:
while (Counter < 5)
{
ActualGrowth = Population[Counter] + MathPercentage;
Counter++;
Population[Counter] = ActualGrowth + Population[Counter--];
}
for (int i = 0; i < Population.Length; i++)
{
Console.WriteLine("Population of 201{0:d}", Years[i]);
Console.WriteLine(Population[i]);
}
while(计数器<5)
{
实际增长=总体[计数器]+百分比;
计数器++;
人口[计数器]=实际增长+人口[计数器--];
}
for(int i=0;i
您将输入的数字在增长百分比上是无限的:
这个也可以帮助你
while (Counter < 5)
{
ActualGrowth = Population[Counter] + MathPercentage;
Counter++;
Population[Counter] = ActualGrowth + Population[Counter-1];
}
for (int i = 0; i < Population.Length; i++)
{
Console.WriteLine("Population of 201{0:d}", Years[i]);
Console.WriteLine(Population[i]);
}
while(计数器<5)
{
实际增长=总体[计数器]+百分比;
计数器++;
人口[计数器]=实际增长+人口[计数器-1];
}
for(int i=0;i
因此,当您使用此代码输入增长百分比时:
while (Counter < 5)
{
ActualGrowth = Population[Counter] + MathPercentage;
Counter++;
Population[Counter] = ActualGrowth + Population[Counter--];
}
for (int i = 0; i < Population.Length; i++)
{
Console.WriteLine("Population of 201{0:d}", Years[i]);
Console.WriteLine(Population[i]);
}
while(计数器<5)
{
实际增长=总体[计数器]+百分比;
计数器++;
人口[计数器]=实际增长+人口[计数器--];
}
for(int i=0;i
您将输入的数字在增长百分比上是无限的:
这个也可以帮助你
while (Counter < 5)
{
ActualGrowth = Population[Counter] + MathPercentage;
Counter++;
Population[Counter] = ActualGrowth + Population[Counter-1];
}
for (int i = 0; i < Population.Length; i++)
{
Console.WriteLine("Population of 201{0:d}", Years[i]);
Console.WriteLine(Population[i]);
}
while(计数器<5)
{
实际增长=总体[计数器]+百分比;
计数器++;
人口[计数器]=实际增长+人口[计数器-1];
}
for(int i=0;i
我猜是这样的:人口[WhileCounter]=实际增长+人口[WhileCounter--];你在减少WhileCounter,使它总是0@ThomasOwers猜猜看,托马斯说了什么。只需将其更改为Population[WhileCounter]=实际增长+Population[WhileCounter-1]@ThomasOwers:应该把这条评论作为答案发布。@EdS。哦,当时只有99%的把握!我猜是这样的:人口[WhileCounter]=实际增长+人口[WhileCounter--];你在减少WhileCounter,使它总是0@Thoma