| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 346 人关注过本帖
标题:求高手帮忙看看那边错误
只看楼主 加入收藏
wxwllb5
Rank: 1
等 级:新手上路
帖 子:11
专家分:3
注 册:2013-1-29
结帖率:66.67%
收藏
已结贴  问题点数:10 回复次数:3 
求高手帮忙看看那边错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            Boolean flag;
          input:
            Console.WriteLine("请输入数A:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入数B:");
            b = Convert.ToInt32(Console.ReadLine());
            if (a > b)
            {
                Console.WriteLine("A>B");
                flag = true;

            }
            else
            {
                Console.WriteLine("A<B");
                flag = false;
            }
        }
    if (flag == false)
        {
        goto input;
        }
        }
    }
}
这后面编译不通过,怎么错误啊,求解释
搜索更多相关主题的帖子: namespace static 
2013-02-22 13:51
chenbb
Rank: 1
等 级:新手上路
帖 子:16
专家分:5
注 册:2013-2-4
收藏
得分:5 
if (flag == false)
        {
        goto input;
        }
       }//这个括号多了去掉就好了
2013-02-22 14:22
adamal
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2013-2-9
收藏
得分:5 
报错的时候记得看错误代码去解决问题。你定义的bool类型变量flag,与你最后一个if语句不在同一个作用域中。你这些代码,根本就不用flag变量,你仔细看一下,flag基本上没用。如果一定要用flag,为什么不定义变量时就赋一个false的值给它呢?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
             int a, b;
            Boolean flag;
          input:
            Console.WriteLine("请输入数A:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入数B:");
            b = Convert.ToInt32(Console.ReadLine());
            if (a > b)
            {
                Console.WriteLine("A>B");
                flag = true;
                Console.ReadKey();

            }
            else
            {
                Console.WriteLine("A<B");
                flag = false;
                goto input;

            }
        }
        }
}
2013-02-22 16:07
adamal
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2013-2-9
收藏
得分:0 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
         
                bool flag = false;
            input:
                Console.WriteLine("请输入A的值");
                int a = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入B的值");
                int b = int.Parse(Console.ReadLine());
                if (a > b)
                {
                    Console.WriteLine("您输入的值a>b,符合要求");
                    Console.ReadKey();
                }
                else if(a==b)
            {
            Console.WriteLine("您输入的值a=b,符合要求");
            Console.ReadKey();
            }
            else if(a < b)
            {
            Console.WriteLine("您输入的值因为a<b,所以请重新输入");
                goto input;

            }
        }
        }
}
2013-02-22 16:20
快速回复:求高手帮忙看看那边错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014792 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved