从初始百分比中减去,但仅当用户输入时;否"/假C#
在我的代码中,接下来的问题是,我有几个if语句需要用户输入。我想设置一个数字(100),如果用户输入=no,那么x number从100中扣除,但是我需要它,比如说第一个用户说no,(100-y)=a,然后第二个用户说no,他的值将扣除a-y 这些计数器正在用于其他用途。我对C#有点陌生,希望它有意义,感谢所有的帮助从初始百分比中减去,但仅当用户输入时;否"/假C#,c#,string,C#,String,在我的代码中,接下来的问题是,我有几个if语句需要用户输入。我想设置一个数字(100),如果用户输入=no,那么x number从100中扣除,但是我需要它,比如说第一个用户说no,(100-y)=a,然后第二个用户说no,他的值将扣除a-y 这些计数器正在用于其他用途。我对C#有点陌生,希望它有意义,感谢所有的帮助 namespace Ice_Cream { class Program { static void Main(string[] args)
namespace Ice_Cream
{
class Program
{
static void Main(string[] args)
{
int counter = 0;
int counter2 = 0;
int counter3 = 0;
int PercentageDisklikes = 100;
string[] Foods = { "Icecream" , "Coffee" , "Sweetpotato" };
string[] Dislike = { "5", "10", "3" };
Console.WriteLine(Foods[0]);
string Icecream = Console.ReadLine();
Console.WriteLine("Do you like Ice cream? " );
if (Icecream == "yes")
{
counter++;
Console.WriteLine("Amount of ppl that like Ice cream: " + counter);
}
if (Icecream == "no")
{
counter2++;
Console.WriteLine("Amount of ppl that don't like Ice cream " + counter2);
Console.WriteLine("Study shows 10% of people agree with you");
// Here i would like int PercentageDisklikes = 100 - 5 to then
//Console.WriteLine("Ovr satisfaction (= 100 -5)
}
else if (Icecream == "maybe")
{
counter2++;
counter3++;
Console.WriteLine("Amount of ppl that don't like Ice cream : " + counter2);
Console.WriteLine("Amount of ppl that maybe don't like Ice cream: " + counter3);
// Here i would like int PercentageDisklikes = 100 - 5 to then
//Console.WriteLine("Ovr satisfaction (= 100 -5)
}
Console.WriteLine(Foods[1]);
string Coffee = Console.ReadLine();
Console.WriteLine("Do you like Coffee? ");
if (Coffee == "yes")
{
counter++;
Console.WriteLine("Amount of ppl that like Coffee: " + counter);
}
if (Coffee == "no")
{
counter2++;
Console.WriteLine("Amount of ppl that don't like Coffee " + counter2);
Console.WriteLine("Study shows 10% of people agree with you");
// Here i would like int PercentageDisklikes = 95 - 5 to then (95 from previous result)
//Console.WriteLine("Ovr satisfaction (= 95 -5)
}
else if (Coffee== "maybe")
{
counter2++;
counter3++;
Console.WriteLine("Amount of ppl that don't like Coffee : " + counter2);
Console.WriteLine("Amount of ppl that maybe don't like Coffee : " + counter3);
// Here i would like int PercentageDisklikes = 95 - 5 to then
//Console.WriteLine("Ovr satisfaction" + PercentageDislikes (= 95 -5)
}
我也不明白你到底想要什么。如果你有更多的问题问。我对C也是新手,我可以告诉你,它不是Python语言:-)
我将以以下方式处理它。数一数你问这个问题的次数。计算每个问题的答案。显示结果
double numberAsked = 0;
double yesIcecream = 0, noIcecream = 0, maybeIcecream = 0;
while (true) // have a nice way to exit in your app
{
Console.WriteLine("Do you like Ice cream? ");
string answer = Console.ReadLine();
numberAsked++;
if (answer == "yes")
{
yesIcecream++;
}
else if (answer == "no")
{
noIcecream++;
}
else if (answer == "maybe")
{
maybeIcecream++;
}
Console.WriteLine($"yes: { yesIcecream / numberAsked * 100}%");
Console.WriteLine($"no: { noIcecream / numberAsked * 100 }%");
Console.Write($"maybe: { maybeIcecream / numberAsked * 100 }%\n\n");
}
无法理解您的问题发布您的试用代码,您发布的代码似乎不是您的试用代码`然后x数字从100中扣除,但我需要它,所以请说出第一个说不的用户,(100-y)=a`哪里是
y
的来源?C#或者不是,您可以访问的只是循环和分支(如果,开关语句),乐高有更多的自由度。因此,当您调试此代码并逐步完成代码时,您是否知道哪些不适合您?这里的关键词是debug,真的不清楚。这段代码中有很多奇怪的东西。变量名。一些指定属性(冰激凌==“可能”)
。分号缺失,分号缺失放置+计数器;)代码>。我建议花3分钟阅读。然后澄清你的问题。用简单的句子来解释上下文。
double numberAsked = 0;
double yesIcecream = 0, noIcecream = 0, maybeIcecream = 0;
while (true) // have a nice way to exit in your app
{
Console.WriteLine("Do you like Ice cream? ");
string answer = Console.ReadLine();
numberAsked++;
if (answer == "yes")
{
yesIcecream++;
}
else if (answer == "no")
{
noIcecream++;
}
else if (answer == "maybe")
{
maybeIcecream++;
}
Console.WriteLine($"yes: { yesIcecream / numberAsked * 100}%");
Console.WriteLine($"no: { noIcecream / numberAsked * 100 }%");
Console.Write($"maybe: { maybeIcecream / numberAsked * 100 }%\n\n");
}