编程1(C#) [英] Programmering 1 (C#)

查看:79
本文介绍了编程1(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


嗨!

我想创建一个对应主鳕鱼的方法,但我不成功,你能帮助我吗?我怎么做用户可以选择多少骰子随机。 




staticintRullaTärning(inttärningar )
$
        {

解决方案

你好,


当发布代码表明什么不起作用时,发布代码在代码块中并发布所有代码。我接受了你的代码并使其完整但不会按原样运行因为抛出新的NotImplementedException,因为它不清楚这两个
方法的意图。

使用系统; 
使用System.Collections.Generic;
使用System.Threading;

名称空间ConsoleApp1
{
class Program
{
///< summary>
/// unused
///< / summary>
///< param name ="tärningar">< / param>
///< returns>< / returns>
staticintRullaTärning(inttärningar)
{
throw new NotImplementedException(); //你离开了逻辑
}

static void Main(string [] args)
{
Random slumpTal = new Random();
List< int> tärningar= new List< int>();
boolkör= true;
while(kör)
{
Console.WriteLine(" \\\
\tVälkommentottärningsgeneratorn:");
Console.Write(" \ n\ [1]Rullatärning:");
Console.Write(" \ n\ [2] Kolla vad du rullade:");
Console.Write(" \ n\ [3] Avsluta:");
Console.Write(" \\\
\tVälja:");
int val;
int.TryParse(Console.ReadLine(),out val);
switch(val)
{
case 1:
Console.Write(" \\\
\hHurångtaärningarvilldu rulla:");
bool inmatning = int.TryParse(Console.ReadLine(),out int antal);
if(inmatning)
{
for(int i = 0; i< antal; i ++)
{$ b $btärningar.Add(RullaTärning(slumpTal));
}
}

休息;
案例2:
int sum = 0;
if(tärningar.Count< = 0)
{
Console.WriteLine(" \ n\tDet finns ingasparadetärningsrull!");
}
else
{
Console.WriteLine(" \\\
\tRullatärningar:");
foreach(tärning在tärningar)
{
Console.WriteLine(" \t" +tärning);
}

Console.WriteLine(" \\\
\tMedelvärdetpåallatärningasrull:" + sum);
}

休息;
case 3:
Console.WriteLine(" \\\
\tTackförattdurulladetärning!");
Thread.Sleep(1000); $ b $bkör= false;
休息;
默认值:
Console.WriteLine(" \ nn \tVälj1-3frånmeny。");
休息;
}
}
}
///< summary>
///你没有显示这个
///< / summary>
///< param name =" slumpTal">< / param>
///< returns>< / returns>
private staticintRullaTärning(Random slumpTal)
{
throw new NotImplementedException();
}
}
}



Hi!
I want to create a method that corespond the Main cod but I'm not success, can you help me. How I can do it. User can chose how many Dice can random. 

static int RullaTärning(int tärningar)
        {

解决方案

Hello,

When posting code indicate what is not working, post the code in a code block and post all of the code. I took your code and made it whole but will not run as is because of the throw new NotImplementedException as it's unclear of the intent for these two methods.

using System;
using System.Collections.Generic;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        /// <summary>
        /// unused
        /// </summary>
        /// <param name="tärningar"></param>
        /// <returns></returns>
        static int RullaTärning(int tärningar)
        {
            throw new NotImplementedException(); // you left logic out
        }

        static void Main(string[] args)
        {
            Random slumpTal = new Random();
            List<int> tärningar = new List<int>();
            bool kör = true;
            while (kör)
            {
                Console.WriteLine("\n\tVälkommen till tärningsgeneratorn: ");
                Console.Write("\n\t[1] Rulla tärning: ");
                Console.Write("\n\t[2] Kolla vad du rullade: ");
                Console.Write("\n\t[3] Avsluta: ");
                Console.Write("\n\tVälja: ");
                int val;
                int.TryParse(Console.ReadLine(), out val);
                switch (val)
                {
                    case 1:
                        Console.Write("\n\tHur många tärningar vill du rulla: ");
                        bool inmatning = int.TryParse(Console.ReadLine(), out int antal);
                        if (inmatning)
                        {
                            for (int i = 0; i < antal; i++)
                            {
                                tärningar.Add(RullaTärning(slumpTal));
                            }
                        }

                        break;
                    case 2:
                        int sum = 0;
                        if (tärningar.Count <= 0)
                        {
                            Console.WriteLine("\n\tDet finns inga sparade tärningsrull! ");
                        }
                        else
                        {
                            Console.WriteLine("\n\tRulla tärningar: ");
                            foreach (int tärning in tärningar)
                            {
                                Console.WriteLine("\t" + tärning);
                            }

                            Console.WriteLine("\n\tMedelvärdet på alla tärningasrull: " + sum);
                        }

                        break;
                    case 3:
                        Console.WriteLine("\n\tTack för att du rullade tärning! ");
                        Thread.Sleep(1000);
                        kör = false;
                        break;
                    default:
                        Console.WriteLine("\n\tVälja 1-3 från meny. ");
                        break;
                }
            }
        }
        /// <summary>
        /// You didn't show this
        /// </summary>
        /// <param name="slumpTal"></param>
        /// <returns></returns>
        private static int RullaTärning(Random slumpTal)
        {
            throw new NotImplementedException();
        }
    }
}


这篇关于编程1(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆