2016-10-04 85 views
-4

我有一個程序,有兩個文本框輸入。它們是variableOne和VariableTwo。我無法弄清楚我需要在for循環中顯示這些數字和它們之間的數字的表達式。例如,如果我把1和11我需要2-10之間。這是我迄今爲止..我知道我還沒有其他表達式。如何讓'while'循環在數字之間計數?

namespace loops 
{ 
    public partial class Form1 : Form 
    { 

     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void whileButton_Click(object sender, EventArgs e) 
     { 
      double variableOne = 0; 
      double variableTwo = 0; 
      int i = 0; 


      if (double.TryParse(variableOneText.Text, out variableOne)) 
      { 
       if(double.TryParse(variableTwoText.Text, out variableTwo)) 
       { 
        while(i<= (variableOne) && (variableTwo)) 
        { 
         i++; 
        } 
        outputLabel.Text = i.ToString(); 

       } 

      } 
     } 
    } 
} 
+2

向我們展示你已經嘗試了什麼。 – IAbstract

+0

我很難試圖瞭解你的問題 – Rahul

+1

我們可以幫助你的代碼,但沒有人會爲你寫,顯示你到目前爲止 – RobertPeric

回答

0

目前仍不清楚你想實現什麼。

我猜猜這裏:

輸入:兩個有理數。 輸出:中間的所有自然數。

例如8.1,14.9 - > OUT 9,10,11,12,13

這裏的代碼

StringBuilder output = new StringBuilder(); 
double variableOne = 8.1; 
double variableTwo = 14.9; 

double start = 0; 
double end = 0; 

bool isShowingInitialVariable = true; 


//if (double.TryParse(variableOneText.Text, out variableOne)) 
//{ 
// if (double.TryParse(variableTwoText.Text, out variableTwo)) 
// { 


//take allways the smaller number to start and the greater for end 
start = Math.Min(variableOne, variableTwo); 
end = Math.Max(variableOne, variableTwo); 

//build your output 
output.AppendLine(string.Format("first variable {0}, second variable {1}", variableOne, variableTwo)); 
output.AppendLine(string.Format("min", start)); 
output.AppendLine(string.Format("max", end)); 
output.AppendLine(string.Format("difference {0}", end - start)); 


//all the natural numbers in between. 
for (int i = (int)Math.Ceiling(start); i < Math.Floor(end); i++) 
{ 
    output.AppendLine(i.ToString()); 
} 

Console.WriteLine(output.ToString()); 
//  outputLabel.Text = output.ToString(); 

// } 

//}