windows 形式的 C++ if 语句

C++ if statements in windows forms

我正在尝试制作一个程序来告诉您您的生肖 sign.I 有 2 个用于日和月的文本框、一个按钮和一个用于输出的 richtextbox。我无法使 if 语句起作用,richtextbox 为每个输入显示相同的内容。例如,即使日期是 5 月 7 日,它也会说摩羯座。那么,我怎样才能使 if 语句起作用呢? 我是 C++ Windows 表单和 visual studio 的新手,我知道这是一个无用的程序,我只是想知道这些东西是如何工作的。 这是我在按钮内的代码:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
{
    String ^ input = textBox2->Text;
    String^inputday = textBox1->Text;
    int luna; int day;
    luna = Convert::ToInt32(input);
    day = Convert::ToInt32(inputday);
    {if (luna == 1 && day < 20)

    {
        richTextBox1->Text = "Your sign is Capricorn ";
    }
    else { richTextBox1->Text = "Your sign is Aquarius"; }}


    {   if (luna == 2 && day < 19) { richTextBox1->Text = "Your sign is Aquarius"; }
    else { richTextBox1->Text = "Your sign is Pisces"; }}


    if (luna == 3 && day < 21) { richTextBox1->Text = "Your sign is Pisces"; }
    else { richTextBox1->Text = "Your sign is Aries"; }

    if (luna == 4 && day < 21) { richTextBox1->Text = "Your sign is Aries"; }
    else {
        richTextBox1->Text = "Your sign is Taurus";
    }
    if (luna == 5 && day < 22) { richTextBox1->Text = "Your sign is Taurus"; }
    else {
        richTextBox1->Text = "Your sign is Gemeni";
    }

    if (luna == 6 && day < 22) {
        richTextBox1->Text = "Your sign is Gemeni";
    }
    else { richTextBox1->Text = "Your sign is Cancer"; }

    if (luna == 7 && day < 22) {
        richTextBox1->Text = "Your sign is Cancer";
    }
    else {
        richTextBox1->Text = "Your sign is Leo";
    }

    if (luna == 8 && day < 23) {
        richTextBox1->Text = "Your sign is Leo";
    }
    else {
        richTextBox1->Text = "Your sign is Virgo";
    }

    if (luna == 9 && day < 23) {
        richTextBox1->Text = "Your sign is Virgo";
    }
    else {
        richTextBox1->Text = "Your sign is Libra";
    }

    if (luna == 10 && day < 23) {
        richTextBox1->Text = "Your sign is Libra";
    }
    else { richTextBox1->Text = "Your sign is Scorpio"; }

    if (luna == 11 && day < 22) {
        richTextBox1->Text = "Your sign is Scorpio";
    }
    else {
        richTextBox1->Text = "Your sign is Sagittarius";
    }
    if (luna == 12 && day < 22) {
        richTextBox1->Text = "Your sign is Sagittarius";
    }
    else {
        richTextBox1->Text = "Your sign is Capricorn";
    }

不是C++的问题,是if语句逻辑的问题

应该是这样的:

if (luna == 1)
    if (day < 20)
       //assign value
    else
        //assign value
else if (luna == 2)
    if (day < 19)
        //assign value
    else
        //assign value
else if (luna == 3) //and so on.....