Demonstrate C # BASIC program structure with a small demo--arithmetic problem in the console

Source: Internet
Author: User

/* Write a random math problem, you calculate the answer to the program */
Using System;
Namespace Test {
public class test{
/* Judgment is correct */
public static bool Fun1 (int[] randoms,int readline_info)
{
int right_result = Randoms[0] + randoms[1];
if (Readline_info = = Right_result)
return true;
Else
{
return false;
}
}
/* generates two random integers */
public static int[] Fun2 () {
int[] randoms = new int[2];
int x, y;
Random ran = new random ();
x = ran. Next (1, 100);
y = ran. Next (1, 100);
Randoms[0] = x;
Randoms[1] = y;
Console.WriteLine (x + "+" + y + "=?");
return randoms;
}
public static void Main ()
{
BOOL result = FALSE;
while (result) {
int readline_info;
int[] randoms = fun2 ();
Console.WriteLine ("+");
string to int, using INT. Parse (str), efficient and non-throwing exception
readline_info = Int. Parse (Console.ReadLine ());
Fun1 (randoms, readline_info);
if (result = = True)
Break
}
}
}

}

Demonstrate C # BASIC program structure with a small demo--arithmetic problem in the console

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.