Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
Could someone help me why do i get true only if the numbers are the same? I need to find out if the second input is in the first one. True/false
int[] firstNumber;
firstNumber = new int[10];
firstNumber[0] =
Convert.ToInt32(Console.ReadLine());
int secondNumber =
Convert.ToInt32(Console.ReadLine()) ;
Console.WriteLine(firstNumber.Contains(secondNumber));
Edit. I need to get true for ex.:firstNumber 5214 and secondNumber 4
how can i get true for 5432(firstNum) and 3(secondNum)
Use strings instead of integers, which will use string.Contains instead of Array.Contains:
string firstNumber = Console.ReadLine();
string secondNumber = Console.ReadLine();
Console.WriteLine(firstNumber.Contains(secondNumber));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Does anyone know a logic to divide a number randomly? I need to do this in C#, but it might just be logic here.
Example:
I want to split 10 = 3 + 4 + 1 + 2
I want to split 30 = 2 + 5 + 8 + 4 + 6 + 5
Pseudo Code:
myNumber = 30; //Number to split
int maximumValue = myNumber; //Maximum value we can get with rand()
int totalValue = 0; //Save our total
while(totalValue < myNUmber)
{
newSplitNumber = rand(0, maximumValue); //Use as needed
totalValue+= newSplitNumber; //Update our total
maximumValue = myNumber - totalValue; //Update our maximum on next iteration
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm currently working on a hotel management system's invoice (asp.net c#)... My question is that how to show the round off on a label example if the total amount is 8023.25 round off label should show .25 and totallabel should show 8023...
Please can anybody help me with this {with code} ???
You can do it mathematically:
Get the integral part by casting it with int.
To get the decimal portion, deduct the total amount with the intergral portion:
double amt = 8023.25;
int value = (int)amt; //value will become 8023
double fraction = amt - value; //fractionwill become 0.25
You can split it and use them like:
string s = inputValue.ToString("8023.25", CultureInfo.InvariantCulture);
string[] parts = s.Split('.');
int i1 = int.Parse(parts[0]);
int i2 = int.Parse(parts[1]);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Currently, I am trying to convert coffee script from there https://github.com/slang800/instagram-id-to-url-segment to C# but I am unable to convert because I have less exp in coffee script. What I need to do is simple but I am unable to guess the algo. If id is 1038059720608660215 then value should be 5n7dDmhTr3. The complete code of algo is available at github.
Try this
static void Main(string[] args)
{
string[] convert = {
"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","a","b","c","d",
"e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x",
"y","z","0","1","2","3","4","5","6","7",
"8","9","-","_"
};
Int64 input = 1038059720608660215;
string output = "";
for (int i = 9; i >= 0; i--)
{
long digit = (input >> (6 * i)) & 0x3F;
output += convert[digit];
}
Console.WriteLine(output);
Console.ReadLine();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have this code that helps me getting information from texts files , the problem is that i cant get to add all the strings founds in the texts files into one int.
in the first Entrada.txt i have a 23 and in the second one i have 45.
How can i add those 2 numbers together?
foreach(var impressora in ListaImp)
{
var Entrada = File.ReadAllText(impressora + #"\Entrada.txt");
MessageBox.Show("Entrada : " + Entrada);
}
Output: 2345.
I want it to be 23 + 45 = 68
You can do this:
int sub = 0;
foreach(var impressora in ListaImp)
{
var Entrada = File.ReadAllText(impressora + #"\Entrada.txt");
sub += int.Parse(Entrada);
}
MessageBox.Show(sub.ToString());