有人可以帮我修改我的代码(C#)吗? [英] Can someone help me fix my code (C#)?
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VI2
{
class Program
{
private const string V = "iniciar";
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("------------------------ PIP-OS(R) 7.1.0 --------------------- ");
System.Threading.Thread.Sleep(5000);
Console.WriteLine(" > FREEWARE ROBCO(R)");
System.Threading.Thread.Sleep(1000);
Console.WriteLine(" > EXEC VERSION 41.10");
System.Threading.Thread.Sleep(1000);
Console.WriteLine(" > 64K RAM SYSTEM");
System.Threading.Thread.Sleep(1000);
Console.WriteLine(" > 4815162342 BYTES FREE");
System.Threading.Thread.Sleep(1000);
Console.WriteLine(" > NO HOLOTAPE FOUND");
System.Threading.Thread.Sleep(1000);
Console.WriteLine(" > LOAD ROM(1):DEITRIX 303");
System.Threading.Thread.Sleep(1000);
Console.WriteLine("");
System.Threading.Thread.Sleep(1000);
Console.WriteLine("> start");
Console.WriteLine("");
do
{
string choice = Console.ReadLine();
switch (choice)
{
case "iniciar":
{
Console.WriteLine(" Olá,eu sou uma demonstração de inteligência artificial criada por Ezequiel Santos");
Console.Title = "AI";
Console.WriteLine("Qual é o seu nome?");
string nome = Console.ReadLine();
Console.WriteLine("Bem vindo, " + nome + " , como poderei ajudar hoje?");
do
{
switch (Console.ReadLine())
{
case "horas": // Do Something
{
// Display the date/time when this method got called.
Console.WriteLine("São: " + DateTime.Now);
// Force a garbage collection to occur for this demo.
GC.Collect();
}
break;
case "Horas": // Do Something
{
// Display the date/time when this method got called.
Console.WriteLine("São: " + DateTime.Now);
// Force a garbage collection to occur for this demo.
GC.Collect();
}
break;
case "HORAS": // Do Something
{
// Display the date/time when this method got called.
Console.WriteLine("São: " + DateTime.Now);
// Force a garbage collection to occur for this demo.
GC.Collect();
}
break;
case "Tudo bem?": // Do Something
{
Console.WriteLine("Sim,e contigo?");
}
break;
case "TUDO BEM?": //Do that
{
Console.WriteLine("SIM E CONTIGO?");
}
break;
case "tudo bem?": //Do that
{
Console.WriteLine("Sim,e contigo?");
}
break;
case "tudo belho?": //Do that
{
Console.WriteLine("ya belhote");
}
break;
case "sup": //Do that
{
Console.WriteLine("sup");
}
break;
case "IDIOTA": //Do that
{
Console.WriteLine("IDIOTA ES TU");
}
break;
case "idiota": //Do that
{
Console.WriteLine("IDIOTA ES TU");
}
break;
case "ok": //Do that
{
Console.WriteLine("Ok!");
}
break;
case "OK": //Do that
{
Console.WriteLine("Ok!");
}
break;
case "sim esta tudo bem": //Do that
{
Console.WriteLine("Ainda bem,queres saber as novidades?");
}
break;
case "SIM ESTA TUDO BEM": //Do that
{
Console.WriteLine("ACHO BEM!!!!");
}
break;
case "Yep": //Do that
{
Console.WriteLine("Ainda bem,queres saber as novidades?");
}
break;
case "La se vai": //Do that
{
Console.WriteLine("Acho bem que sim,há que continuar!");
}
break;
case "Não": //Do that
{
Console.WriteLine("Não te preocupes,tudo irá melhorar");
}
break;
case "NÃO": //Do that
{
Console.WriteLine("Não te preocupes,tudo irá melhorar");
}
break;
case "nope": //Do that
{
Console.WriteLine("Não te preocupes,tudo irá melhorar");
}
break;
case "não": //Do that
{
Console.WriteLine("Não te preocupes,tudo irá melhorar");
}
break;
case "Novidades": //Do that
{
Console.WriteLine("Ouvi dizer que há um grupo do liceu fernão magalhães que está a tentar criar uma..inteligência artificial...que mestres!!! ");
}
break;
case "NOVIDADES": //Do that
{
Console.WriteLine("Ouvi dizer que há um grupo do liceu fernão magalhães que está a tentar criar uma..inteligência artificial...que mestres!!! ");
}
break;
case "novidades": //Do that
{
Console.WriteLine("Ouvi dizer que há um grupo do liceu fernão magalhães que está a tentar criar uma..inteligência artificial ...que mestres!!! ");
}
break;
case "És mesmo uma inteligência artificial?": //Do that
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "és mesmo uma inteligência artificial?": //Do that
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "Es mesmo uma inteligencia artificial?":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "es mesmo uma inteligencia artificial?":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "És mesmo uma inteligência artificial": //Do that
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "és mesmo uma inteligência artificial": //Do that
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "Es mesmo uma inteligencia artificial":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "es mesmo uma inteligencia artificial":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "És uma AI?":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "És uma AI":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "és uma AI?":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "és uma AI":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "es uma AI?":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "es uma AI":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "Es uma AI?":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "Es uma AI":
{
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
}
break;
case "O que és?":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "o que és?":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "O que es?":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "o que es?":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "O que és":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "o que és":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "O que es":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "o que es":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "Quem és?":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "quem és?":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "Quem és":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "quem és":
{
Console.WriteLine("Antes de mais,não,não sou uma inteligência artificial,isto por que para ser uma AI-IA teria de ser capaz de opinar por mim próprio,ter a capacidade de fazer decisões,e livre-arbítrio,etc");
}
break;
case "Quem te fez?":
{
Console.WriteLine("Ezequiel Santos,um programador de c#!");
}
break;
case "quem te fez?":
{
Console.WriteLine("Ezequiel Santos,um programador de c#!");
}
break;
case "Quem te fez":
{
Console.WriteLine("Ezequiel Santos,um programador de c#!");
}
break;
case "quem te fez":
{
Console.WriteLine("Ezequiel Santos,um programador de c#!");
}
break;
case "calculator":
{
double result = 0;
double firstNumber = SetNumber("Type you first number : ");
double secondNumber = SetNumber("Type you second number: ");
string stringOperation =
SetOperation(
"Enter the operation + (addition), - (soustraction), * (multiplication), / (division), ^ (exposant) or % (reste) :");
switch (stringOperation)
{
case "+":
case "addition":
result = firstNumber + secondNumber;
break;
case "-":
case "soustraction":
result = firstNumber - secondNumber;
break;
case "*":
case "multiplication":
result = firstNumber * secondNumber;
break;
case "/":
case "division":
result = firstNumber / secondNumber;
break;
case "^":
case "exposant":
result = Math.Pow(firstNumber, secondNumber);
break;
case "%":
case "reste":
result = firstNumber % secondNumber;
break;
}
Console.WriteLine("Result of {0} {1} {2} = {3}", firstNumber, stringOperation, secondNumber, result);
Console.ReadKey();
}
break;
}
} while (choice != "0");
}
}
}
{
}
private static string choice;
private static string mudar;
private static readonly string[] operations = { "+", "-", "*", "/", "^", "%" };
private static double SetNumber(string outputText)
{
double parse;
Console.Write(outputText);
string tempInput = Console.ReadLine();
while (!double.TryParse(tempInput, out parse))
{
Console.WriteLine("Incorrect input !");
Console.Write(outputText);
tempInput = Console.ReadLine();
}
return double.Parse(tempInput);
}
private static bool IsValidOperation(string input)
{
return operations.Contains(input);
}
private static string SetOperation(string outputText)
{
Console.Write(outputText);
string tempInput = Console.ReadLine();
while (!IsValidOperation(tempInput))
{
Console.WriteLine("Incorrect input !");
Console.Write(outputText);
tempInput = Console.ReadLine();
}
return tempInput;
}
}
}
我的尝试:
智能感所说的一切,但我无法弄清楚,我只是一个新手
之前有人问为什么是这很奇怪,它只是为了一个班级工作xD
What I have tried:
everything what intelli sense said,but i can't figured it out,im just a newbie
Before someone asks why is it that weird,it is just for a class work xD
推荐答案
首先看一下错误列表窗格 - 它没有打开然后你应该!按CTRL + W,然后按E,它将出现。
每个编译错误都有一个数字,一条消息,一个文件,一个行号,一个列号和一个项目:
Start by looking at the "Error List" pane - it you don't have it open then you should! Press CTRL+W then E and it'll appear.
Each compilation error has a number, a message, a file, a Line number, a column number, and a project:
Error 1 } expected D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs 490 14 GeneralTestingConsole
如果你双击错误会直接到你不喜欢的行。
在这种情况下,这是你的代码,它是第一个错误信息 - 它期待一个}而不是{。为什么?因为你在这里丢失了一些东西 - 你有两个do循环,但只有一个while结束它们,依此类推。
我强烈建议你复制一下code (so you can go back to it if you mess it up completely) and refactor it to use more methods.
Take your outer switch
and make each case
a separate method: That'll be pretty simpel at the moment, because there is only one case
in it!
And if you double click on the error it will take you direct to the line it doesn't like.
In this case this is from your code, and it's the first error message - it's expecting a "}" rather than an "{". Why? Because you have got bits missing here - you have two "do" loops, but only one "while" to end them, and so on.
I'd strongly suggest that you make a copy of that code (so you can go back to it if you mess it up completely) and refactor it to use more methods.
Take your outer switch
and make each case
a separate method: That'll be pretty simpel at the moment, because there is only one case
in it!
switch (choice)
{
case "iniciar":
{
UserIniciar();
break;
}
...
}
Then it’s obvious that you missed out the break
at the end of the case, and the structure of your main
method becomes clearer. Repeat this for your inner case
es and your code should start to become more manageable and easier to correct!
Then it's obvious that you missed out the break
at the end of the case, and the structure of your main
method becomes clearer. Repeat this for your inner case
es and your code should start to become more manageable and easier to correct!
The main problem is that it doesn’t compile. This has two reasons:
1. The curly braces don’t match up.
2. The firstdo
has no matching while.
After fixing that, as far as I can tell, without being able to read Portuguese, it’s a functional command interpreter.
Another problem however is that your code is going to be very hard to maintain with all the duplication. Instead of handling all the command variations with capitals, I would convert the input to lower case and check for that. For cases with accents, you don’t need to duplicate the flow. For example:
The main problem is that it doesn't compile. This has two reasons:
1. The curly braces don't match up.
2. The firstdo
has no matching while.
After fixing that, as far as I can tell, without being able to read Portuguese, it's a functional command interpreter.
Another problem however is that your code is going to be very hard to maintain with all the duplication. Instead of handling all the command variations with capitals, I would convert the input to lower case and check for that. For cases with accents, you don't need to duplicate the flow. For example:
switch (Console.ReadLine().ToLower()) {
case "és mesmo uma inteligência artificial?":
case "es mesmo uma inteligencia artificial?":
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
break;
case "és uma ai?":
case "es uma ai?":
Console.WriteLine("Não,não sou,isto por que,uma inteligência artificial seria capaz de opinar por si própria,ter uma opinião e ter a capacidade de fazer decisões,etc");
break;
}
这篇关于有人可以帮我修改我的代码(C#)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!