While doesn't approve true requirement [closed] - c#

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Variable i will be 0 in the end. Am I having serious problem in visual studio or in my brain?
double value = 0.0001;
int i = 0;
while(value < 0)
{
value *= 10;
i++;
}
Console.WriteLine(i);
Console.ReadLine();

The code inside the while block never runs because your while condition is actually false.
Your condition:
0.0001 < 0
This is a false statement so the while block is skipped.

Related

C# , How to have code wait for user input before moving on to do Math [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
Hi I am in the process of Learning C#, trying to write a short Console Program that will take a users age and convert it into dog years.
The issue I am having is it doesn't wait for the user input, so it assigns 0 as the value then returns 0 (because 0*7 = 0 ) for dog Age
How do I get the code to stop running until the user enters a value
My code :
Console.WriteLine("what is your age?");
string humanAge = Console.ReadLine();
int dogAge = Convert.ToInt32(humanAge) * 7;
Console.WriteLine(dogAge);
This was an issue with the Code Academy App not the code as mariocatch stated ; closing the question

Value not sticking in return value for a list (C#) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
There is probably a simple answer but while practicing some questions on hacker rank the "aScore" isn't saying at a certain value, the first value in a[i] is greater than b[i]. I've been trying to debug the code but I can't print what I want to the console on hacker rank, it's forced to come out to the answer's output somehow.
public static List<int> compareTriplets(List<int> a, List<int> b)
{
int aScore=0;
for(int i=0; i ==(a.Count-1);i++)
if (a[i]>b[i]){
aScore++;
}
return new List<int>(){aScore,1} ;
}
}
for(int i=0; i ==(a.Count-1);i++) should be for(int i=0; i < a.Count; i++)
The for loop executes and iterates as long as the condition (second "part") resolves to true.
In your original code, it does not: 0 does not equal a.Count-1, so the loop body is not executed even once.

"else cannot start a statement" issue [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I tried making a program where every few seconds a random letter dropped. I noticed that the "correct" one dropped to rarely. I made a int correctLetterDrop = Random.Range(0,100) and wanted to artificially increase the chance. The rest of the code handles everything, i just need to assign the correct sprite to check against.
This gives me an error at the .correctSprite; saying "else cannot start a statement". I expect it to just check if the Random.Range returned 7 or less (for a 7% chance) and if it did to set the correct one, and otherwise just set a random one.
if(correctLetterDrop <= 7){
Clone.GetComponent<SpriteRenderer>().sprite = correctLetterScript.correctSprite;
else{
Clone.GetComponent<SpriteRenderer>().sprite = Letters[Letter];
}
}
Check for the first if condition closure }:
if(correctLetterDrop <= 7) {
Clone.GetComponent<SpriteRenderer>().sprite = correctLetterScript.correctSprite;
}else{
Clone.GetComponent<SpriteRenderer>().sprite = Letters[Letter];
}

C# Length method [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm looking how to use correctly the Lenght method, I'm not c# developer, first time looking into code so basically try to get throw using documentation, so I build an validation code that uses string.IsNullOrEmpty to check if the fieldName.name is either empty or null, this is working
var namepropName = PathFinder<InfoField>.Get(i => i.fieldName.name);
RegValidation(namepropName, (x, y) => {
ValueRequired(, () => string.IsNullOrEmpty(x.fieldName.name));
});
Now I trying to check if the fieldName.name length is bigger than 20 characters.
The below code is throwing errors, how can I use string.Length is bigger than 20 correctly?
ValueRequired(, () => string.Length > 20 (x.fieldName.name));
ValueRequired(, () => x.fieldName.name.Length > 20);

Why logical evaluation is not stopped on fist "false" result? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
testExceptions is Dictionary.
var testConfigurations = cells.SelectMany(x => x.TestConfigurations).Where(
y => y.ID == testId &&
!testExceptions[index].ContainsKey(y.Cell) &&
!testExceptions[index][y.Cell].Contains(y.ID)
).ToList();
!testExceptions[index][y.Cell].Contains(y.ID) is giving me an exception when testExceptions doesn't contain key y.Cell. But since I was checking ContainsKey I expected it will not evaluate last condition. Is there any way to avoid exception without using long if/else statements?
You're checking if it doesn't contain the key. You need to check if it does contain the key:
testExceptions[index].ContainsKey(y.Cell) && ... use the key ...

Categories