2017-06-24 1 views
0

私はC#windowsフォームアプリケーションプログラムを作成しました。これには上限と下限のユーザー入力があり、出力は10から始まり、上限。私のプログラムは何も出力せず、何が間違っているのか分かりません。上限よりも低くなっている10のユーザー入力とループでプログラムに何も出力されていません

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 Loops 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private int lowerBounds, upperBounds, num; 

    private void TextBoxUpperBounds_TextChanged(object sender, EventArgs e) 
    { 
     upperBounds = Convert.ToInt32(Console.ReadLine()); 
    } 

    private void BtnOutputValues_Click(object sender, EventArgs e) 
    { 
     for (num = lowerBounds; num < upperBounds; num++) 
     { 
      if (num % 10 == 0) 
      { 
       MessageBox.Show(num.ToString()); 
      } 
      else { } 

     } 
    }   

    private void TextBoxLowerBounds_TextChanged(object sender, EventArgs e) 
    { 
     lowerBounds = Convert.ToInt32(Console.ReadLine()); 
    } 
} 

}

+1

あなたが読んでいるのはなぜFormsアプリケーション – Jimbot

+0

にあるときは、 'コンソールから(' Console.ReadLIne())の値を読み取ることができませんテキストボックスの変更イベントのコンソール?テキストボックス(TextBoxUpperBounds.Text)の値を読んではいけません。 – atomSmasher

+0

TextBoxUpperBounds.Textで入力を読み込みますか? –

答えて

0

atomSmasherは完全に正しかったです。ここで私はそれを行うために必要な正確に何を行うコードは次のとおりです。

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 Loops 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
       InitializeComponent(); 
     } 

     private int lowerBounds, upperBounds, num; 

     private void TextBoxUpperBounds_TextChanged(object sender, EventArgs e) 
     { 
      upperBounds = Convert.ToInt32(textBoxUpperBounds.Text); 
     } 

     private void BtnOutputValues_Click(object sender, EventArgs e) 
     { 
      for (num = lowerBounds; num < upperBounds; num++) 
      { 
       if (num % 10 == 0) 
       { 
        MessageBox.Show(num.ToString()); 
       } 
       else { } 

      } 
     }   

     private void TextBoxLowerBounds_TextChanged(object sender, EventArgs e) 
     { 
      lowerBounds = Convert.ToInt32(textBoxLowerBounds.Text); 
     } 
    } 
} 
0

あなたのコードだけ出力倍数を:ここには、私が持っているものです。あなたがループの下に使用する必要がある10以上である下限と上限の間の数字を出力するようにコードを作成する

for (num = lowerBounds; num < upperBounds; num++) 
    { 
     if (num >10) 
     { 
      MessageBox.Show(num.ToString()); 
     } 
     else { } 

    } 
関連する問題