Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要额外的括号吗?_C#_Brackets - Fatal编程技术网

C# 需要额外的括号吗?

C# 需要额外的括号吗?,c#,brackets,C#,Brackets,以下是: if (parseok == false) { Console.WriteLine("Error : Please enter valid numeric Value "); Console.ReadLine(); Environment.Exit(0); } //Is currently working fine, however, I am wanting to change the if statement to a while loop - for er

以下是:

if (parseok == false)
{
    Console.WriteLine("Error : Please enter valid numeric Value ");
    Console.ReadLine();
    Environment.Exit(0);
}
//Is currently working fine, however, I am wanting to change the if statement to a while loop - for error checking purposes. When I change the code to this :

while (parseok == false)
{
    Console.WriteLine("Error : Please enter valid numeric Value ");
    Console.ReadLine();
    Console.Write("Please enter minutes for your first run:    ");
    parseok = int.TryParse(Console.ReadLine(), out run1m);
}
//I am recieveing an error message saying that I'm missing a close bracket, when I add the close bracket the whole program becomes riddled with errors. What am I forgetting to do?

//I will add the entire project's code : 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp1
    {
        class Program
        {
            //Ajdin Karahodzic 
            //ID : KARAD1301

        static void Main(string[] args)
        {
            String membertype = "";

            //Declaration of Variables 
            string name = "";
            string member = "";
            string gender = "";
            int run1m = 0;
            int run1s = 0;
            int run2m = 0;
            int run2s = 0;
            int run3m = 0;
            int run3s = 0;
            int run1total = 0;
            int run2total = 0;
            int run3total = 0;
            int totalsecs = 0;
            int avgsecs = 0;
            int hours = 0;
            int minutes = 0;
            int seconds = 0;
            bool parseok = false;
            string menu = "";
            int run1tempS = 0;
            int run1tempM = 0;
            int run1tempH = 0;
            int run2tempS = 0;
            int run2tempM = 0;
            int run2tempH = 0;
            int run3tempS = 0;
            int run3tempM = 0;
            int run3tempH = 0;

            while (menu != "x")
            {
                Console.WriteLine("Please choose from the following : ");
                Console.WriteLine("Enter Runner Details (R) : ");
                Console.WriteLine("Enter run times (T) : ");
                Console.WriteLine("Display runner results (D) : ");
                Console.WriteLine("Exit the program (X) ");
                menu = Console.ReadLine();

                switch (menu)
                {
                    //CLOSE PROGRAM SWITCH
                    case "x":
                    case "X":
                        Environment.Exit(0);
                        break;

                    //ENTER RUNNER DATA SWITCH
                    case "r":
                    case "R":
                        Console.Write("Please enter your name:               ");
                        name = Console.ReadLine();

                    while (string.IsNullOrEmpty(name))
                    {
                        Console.WriteLine("Error : Please ensure you have entered your name, press enter to continue ");
                        Console.ReadLine();
                        Console.Write("Please enter your name:               ");
                        name = Console.ReadLine();
                    }

                    Console.Write("Please enter your  membership number: ");
                    member = Console.ReadLine();
                    while (member.Length != 5)
                    {
                        Console.WriteLine("Error : Membership number must be 5 characters long, press enter to continue ");
                        Console.ReadLine();
                        Console.Write("Please enter your  membership number: ");
                        member = Console.ReadLine();
                    }
                    char first = member[0];
                    while (first != 'o' && first != 'O' && first != 's' && first != 'S' && first != 'j' && first != 'J' && first != 'C' && first != 'c')
                    {
                        Console.WriteLine("Error : Membership number must begin with O, S, J or C, press enter to continue ");
                        Console.ReadLine();
                        Console.Write("Please enter your  membership number: ");
                        member = Console.ReadLine();
                    }
                    if (first == 'o' || first == 'O')
                    {
                        membertype = "Ordinary Member";
                    }
                    else if (first == 's' || first == 'S')
                    {
                        membertype = "Student Member";
                    }
                    else if (first == 'j' || first == 'J')
                    {
                        membertype = "Junior Member";
                    }
                    else if (first == 'c' || first == 'C')
                    {
                        membertype = "Child Member";
                    }
                    string response = "";
                    Console.Write("Please enter your gender (m) or (f) : ");
                    response = Console.ReadLine();
                    gender = response;
                    while (gender != "m" && gender != "M" && gender != "f" && gender != "F")
                    {
                        Console.WriteLine("Error : Gender must be either : M / m (For Male) or F / f (For Female), press enter to continues ");
                        Console.ReadLine();
                        Console.Write("Please enter your gender (m) or (f) : ");
                        response = Console.ReadLine();
                        gender = response;
                    }
                    break;

                    //ENTER RUN TIMES - SWITCH
                    case "T":
                    case "t":
                    //Prompt for user input; collect and store data.
                    /*---------RUN 1 INPUT---------
                      -----------------------------*/
                    //MINUTES
                    Console.Write("Please enter minutes for your first run:    ");
                    parseok = int.TryParse(Console.ReadLine(), out run1m);
                    while (parseok == false)
                    {
                        Console.WriteLine("Error : Please enter valid numeric Value ");
                        Console.ReadLine();
                        Console.Write("Please enter minutes for your first run:    ");
                        parseok = int.TryParse(Console.ReadLine(), out run1m);
                    }
                    else if (run1m < 15 || run1m > 180)
                    {
                        Console.WriteLine("Error : Minutes cannot be less than 15 or greater than 180");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    //SECONDS
                    Console.Write("Please enter seconds for your first run:    ");
                    parseok = int.TryParse(Console.ReadLine(), out run1s);
                    if (parseok == false)
                    {
                        Console.WriteLine("Error : Please enter valid numeric Value ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    else if (run1s < 0 || run1s > 59)
                    {
                        Console.WriteLine("Error : Seconds must be between 0 and 59 ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    Console.WriteLine();
                    /*---------RUN 2 INPUT---------
                      ------------------------------*/
                    Console.Write("Please enter minutes for your second run:   ");
                    parseok = int.TryParse(Console.ReadLine(), out run2m);
                    if (parseok == false)
                    {
                        Console.WriteLine("Error : Please enter valid numeric Value ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    else if (run2m < 15 || run2m > 180)
                    {
                        Console.WriteLine("Error : Minutes cannot be less than 15 or greater than 180");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    Console.Write("Please enter seconds for your second run:   ");
                    run2s = int.Parse(Console.ReadLine());
                    if (parseok == false)
                    {
                        Console.WriteLine("Error : Please enter valid numeric Value ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    else if (run2s < 0 || run2s > 59)
                    {
                        Console.WriteLine("Error : Seconds must be between 0 and 59 ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    Console.WriteLine();
                    /*---------RUN 3 INPUT---------
                     ------------------------------*/
                    Console.Write("Please enter minutes for your third run:    ");
                    parseok = int.TryParse(Console.ReadLine(), out run3m);
                    if (parseok == false)
                    {
                        Console.WriteLine("Error : Please enter valid numeric Value ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    else if (run3m < 15 || run3m > 180)
                    {
                        Console.WriteLine("Error : Minutes cannot be less than 15 or greater than 180");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    Console.Write("Please enter seconds for your third run:    ");
                    run3s = int.Parse(Console.ReadLine());

                    if (parseok == false)
                    {
                        Console.WriteLine("Error : Please enter valid numeric Value ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    else if (run3s < 0 || run3s > 59)
                    {
                        Console.WriteLine("Error : Seconds must be between 0 and 59 ");
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                    Console.WriteLine();
                    break;
                    case "d":
                    case "D":
                    // CALCULATIONS
                    //Converting individual run times to seconds
                    run1total = (run1m * 60) + run1s;
                    run2total = (run2m * 60) + run2s;
                    run3total = (run3m * 60) + run3s;
                    //Convert individual times to hours, mins, secs.
                    // RUN1
                    run1tempS = (run1total % 60);
                    run1tempM = ((run1total / 60) % 60);
                    run1tempH = ((run1total / 3600) % 60);
                    // RUN2
                    run2tempS = (run2total % 60);
                    run2tempM = ((run2total / 60) % 60);
                    run2tempH = ((run2total / 3600) % 60);
                    // RUN3
                    run3tempS = (run3total % 60);
                    run3tempM = ((run3total / 60) % 60);
                    run3tempH = ((run3total / 3600) % 60);
                    //Calculate average time
                    totalsecs = (run1total + run2total + run3total);
                    avgsecs = (totalsecs / 3);
                    seconds = (avgsecs % 60);
                    minutes = ((avgsecs / 60) % 60);
                    hours = ((avgsecs / 3600) % 60);
                    //Display results
                    Console.WriteLine();
                    Console.WriteLine("==========================================================================");
                    Console.WriteLine("10 Km results for: ");
                    Console.WriteLine("{0} [{1}] - {2}, {3}  ", name, member, membertype, gender.ToUpper());
                    Console.WriteLine("Run 1 - {0} hr(s) {1} min(s) {2} sec(s). ", run1tempH, run1tempM, run1tempS);
                    Console.WriteLine("Run 2 - {0} hr(s) {1} min(s) {2} sec(s). ", run2tempH, run2tempM, run2tempS);
                    Console.WriteLine("Run 3 - {0} hr(s) {1} min(s) {2} sec(s). ", run3tempH, run3tempM, run3tempS);
                    Console.WriteLine();
                    Console.WriteLine("Average 10km run time is : {0} hours {1} minutes {2} seconds. ", hours, minutes, seconds);
                    break;
                    default:
                      Console.WriteLine("Incorrect input, please try again ");
                      break;
                }
                Console.ReadLine();
            }
        }
    }
}
if(parseok==false)
{
Console.WriteLine(“错误:请输入有效的数值”);
Console.ReadLine();
环境。退出(0);
}
//目前运行良好,但是,我想将if语句更改为while循环-用于错误检查。当我将代码更改为以下内容时:
while(parseok==false)
{
Console.WriteLine(“错误:请输入有效的数值”);
Console.ReadLine();
控制台。写入(“请输入第一次跑步的分钟数:”;
parseok=int.TryParse(Console.ReadLine(),out run1m);
}
//我收到一条错误消息,说我缺少一个右括号,当我添加右括号时,整个程序都充满了错误。我忘记做什么了?
//我将添加整个项目的代码:
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间控制台EAPP1
{
班级计划
{
//阿吉丁·卡拉霍季奇
//ID:KARAD1301
静态void Main(字符串[]参数)
{
字符串membertype=“”;
//变量声明
字符串名称=”;
字符串成员=”;
字符串性别=”;
int run1m=0;
int run1s=0;
int run2m=0;
int run2s=0;
int run3m=0;
int-run3s=0;
int run1total=0;
int run2total=0;
int run3total=0;
int totalsecs=0;
int-avgsecs=0;
整小时=0;
整数分钟=0;
整数秒=0;
bool parseok=false;
字符串菜单=”;
int run1tempS=0;
int run1tempM=0;
int run1tempH=0;
int run2tempS=0;
int run2tempM=0;
int run2tempH=0;
int run3tempS=0;
int run3tempM=0;
int run3tempH=0;
while(菜单!=“x”)
{
Console.WriteLine(“请从以下选项中选择:”);
Console.WriteLine(“输入跑步者详细信息(R):”;
Console.WriteLine(“输入运行时间(T):”;
Console.WriteLine(“显示运行程序结果(D):”;
控制台写入线(“退出程序(X)”;
menu=Console.ReadLine();
开关(菜单)
{
//闭合程序开关
案例“x”:
案例“X”:
环境。退出(0);
打破
//输入RUNNER数据开关
案例“r”:
案例“R”:
控制台。写下(“请输入您的姓名:”);
name=Console.ReadLine();
while(string.IsNullOrEmpty(name))
{
Console.WriteLine(“错误:请确保已输入您的姓名,按enter键继续”);
Console.ReadLine();
控制台。写下(“请输入您的姓名:”);
name=Console.ReadLine();
}
控制台。写下(“请输入您的会员编号:”);
member=Console.ReadLine();
while(member.Length!=5)
{
Console.WriteLine(“错误:会员编号必须为5个字符,按enter键继续”);
Console.ReadLine();
控制台。写下(“请输入您的会员编号:”);
member=Console.ReadLine();
}
char first=成员[0];
而(first!=“o”&&first!=“o”&&first!=“s”&&first!=“s”&&first!=“j”&&first!=“j”&&first!=“C”&&first!=“C”)
{
Console.WriteLine(“错误:会员编号必须以O、S、J或C开头,按enter键继续”);
Console.ReadLine();
控制台。写下(“请输入您的会员编号:”);
member=Console.ReadLine();
}
if(first='o'| | first='o')
{
membertype=“普通会员”;
}
else if(first==“s”| | first==“s”)
{
membertype=“学生成员”;
}
else if(first==“j”| | first==“j”)
{
membertype=“初级成员”;
}
else if(first='c'| | first=='c')
{
membertype=“子成员”;
}
字符串响应=”;
控制台。写下(“请输入您的性别(m)或(f):”;
response=Console.ReadLine();
性别=反应;
while(性别!=“m”&&gender!=“m”&&gender!=“f”&&gender!=“f”)
{
Console.WriteLine(“错误:性别必须为:M/M(男性)或F/F(女性),按enter键继续”);
Console.ReadLine();
控制台。写下(“请输入您的性别(m)或(f):”;
response=Console.ReadLine();
性别=反应;
}
打破
//输入运行时间-开关
案例“T”:
案例“t”:
//提示用户输入;收集和存储数据。
/*---------运行1输入---------
else