24-point program (3)

Source: Internet
Author: User

The last time the system was reinstalled, I accidentally lost all the programs I wrote earlier. Depressed ...................................

However, this 24-point mini-program is almost half done, but it is still designed from the ground up. Fortunately, the previous key materials are written into the blog, so it is faster to restore.

It is now written to use a string to represent the infix expression. After writing for many hours, I found that my experience was not solid. I was confused by a few strings, so I was cheated, asked in the group, and posted my post online. Finally, we finally converted this into a solution. Now we feel a little more refined in understanding the strings.

Below is what I wrote today

Void CMy24pointDlg: OnPrint ()
{
// TODO: Add your control notification handler code here
// Accept the number in the box
/* UpdateData ();
GetDlgItemInt (IDC_NUM1, & RecvNum [0], FALSE );
GetDlgItemInt (IDC_NUM2, & RecvNum [1], FALSE );
GetDlgItemInt (IDC_NUM3, & RecvNum [2], FALSE );
GetDlgItemInt (IDC_NUM4, & RecvNum [3], FALSE );
UpdateData (TRUE );*/
// Update ();
// Determine the range of received numbers
For (int I = 0; I <4; I ++)
{
If (SrandNum [I]> 12 | SrandNum [I] <= 0)
{
MessageBox ("your number is out of the range. Enter the number between 1 and 12 ");
// Return 0;
}
}
 
// Generate an infix expression
// Define an array of characters to store the infix expression
Char buffer [12];

// Use a B c d to add, subtract, and divide.
// The ASCII values of a, B, c, and d are 97, 98, 99, and 100, respectively.
Int add = 97;
Int sub = 98;
Int by = 99;
Int div = 100;
// Configure //------------------------------------------------------------------------------------------
// Use addition, subtraction, multiplication, division, to traverse all Algorithms
For (int first = add; first <= div; first ++)
For (int second = add; second <= div; second ++)
For (int third = add; third <= div; third ++)
{
// The preceding number is converted into a string,
// Add, sub .... Convert to ASCII code and then convert to string


// Use flag1 and flag2 to store the character numbers of the infix expression.
Char flag1 [1], flag2 [1];




// ======================== Set the first number ================================== //
// If the random number is 2 digits
If (SrandNum [0]> = 10)
{
// Use NumBuffer [0] to store the first and NumBuffer [1] to store the second
// Used to store random numbers that generate two digits at random
Int NumBuffer [2];
Int m = 0;
Int temp = SrandNum [0];
While (m <2)
{
NumBuffer [1-m] = temp % 10;
Temp = temp/10;
M ++;
}
Flag1 [0] = NumBuffer [0] + 48;
Flag2 [0] = NumBuffer [1] + 48;
Buffer [0] = flag1 [0];
Buffer [1] = flag2 [0];
}
Else
{
Flag1 [0] = 0 + 48;
Buffer [0] = flag1 [0];
Buffer [1] = SrandNum [0] + 48;
}





// ============================ Set the first symbol ===================== == //
Buffer [2] = first;




// ======================== Set the second number =========================== = //
If (SrandNum [1]> = 10)
{
// Use NumBuffer [0] to store the first and NumBuffer [1] to store the second
// Used to store random numbers that generate two digits at random
Int NumBuffer [2];
Int m = 0;
Int temp = SrandNum [1];
While (m <2)
{
NumBuffer [1-m] = temp % 10;
Temp = temp/10;
M ++;
}
Flag1 [0] = NumBuffer [0] + 48;
Flag2 [0] = NumBuffer [1] + 48;
Buffer [3] = flag1 [0];
Buffer [4] = flag2 [0];
}
Else
{
Flag1 [0] = 0 + 48;
Buffer [3] = flag1 [0];
Buffer [4] = srandnum [1] + 48;
}




// ============================ Set the second symbol ===================== == //
Buffer [5] = second;



// ========================== Set the third number =========================== = //
If (srandnum [2]> = 10)
{
// Use numbuffer [0] to store the first and numbuffer [1] to store the second
// Used to store random numbers that generate two digits at random
Int NumBuffer [2];
Int m = 0;
Int temp = SrandNum [2];
While (m <2)
{
NumBuffer [1-m] = temp % 10;
Temp = temp/10;
M ++;
}
Flag1 [0] = NumBuffer [0] + 48;
Flag2 [0] = NumBuffer [1] + 48;
Buffer [6] = flag1 [0];
Buffer [7] = flag2 [0];
}
Else
{
Flag1 [0] = 0 + 48;
Buffer [6] = flag1 [0];
Buffer [7] = SrandNum [2] + 48;
}




// ============================ Set the third symbol ===================== == //
Buffer [8] = third;





// ========================== Set the fourth number =============================== = //
If (srandnum [3]> = 10)
{
// Use numbuffer [0] to store the first and numbuffer [1] to store the second
// Used to store random numbers that generate two digits at random
Int numbuffer [2];
Int m = 0;
Int temp = srandnum [3];
While (M <2)
{
Numbuffer [1-m] = TEMP % 10;
Temp = temp/10;
M ++;
}
Flag1 [0] = NumBuffer [0] + 48;
Flag2 [0] = NumBuffer [1] + 48;
Buffer [9] = flag1 [0];
Buffer [10] = flag2 [0];
}
Else
{
Flag1 [0] = 0 + 48;
Buffer [9] = flag1 [0];
Buffer [10] = SrandNum [3] + 48;
}




// ============== Set the last end character ============================================ //
Buffer [11] = 0;



}

MessageBox (buffer );
// Configure //---------------------------------------------------------------------------------------

}

When designing the above program, I basically did not think about it. When writing the program, I found that the random number is between 1 and 12. Sometimes the return value is one digit, sometimes two digits, therefore, it is troublesome to handle the problem.

The above code is not complete yet, but there is still a problem with the above Code.

Yes

Getdlgitemint (idc_num1, & recvnum [0], false );
Getdlgitemint (idc_num2, & recvnum [1], false );
Getdlgitemint (idc_num3, & recvnum [2], false );
Getdlgitemint (idc_num4, & recvnum [3], false );

I don't know why I cannot receive the numbers in the dialog box.

I can't use the updatedata () function. It's really strange.

Another thing that is cumbersome is to use a global function to set the number from the first to the fourth.

Now the basic auxiliary measures have been completed.

The following are the real stack applications, and those are the key.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.