How to loop this properly [closed] - c#

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 months ago.
Improve this question
I have tried looping this it didnt work for me please help me im trying to learn c# and it would help alot if you would help me
using System.Text.RegularExpressions;
{
Console.WriteLine("What do you want to check, if its a number or not: ");
int myInt = Convert.ToInt32(Console.ReadLine());
bool isLessThan10000000000 = myInt < 10000000000;
Console.WriteLine("Is it a Number? {0}", isLessThan10000000000);
Console.ReadKey();
Console.WriteLine("Do you want to continue (Y/N)? ");
if (Console.ReadKey().KeyChar == 'Y')
{
}
else
{
}
}

You can use a do while loop
it's about the same as a while loop expect it evaluates the condition after the loop instead of before
do
{
//Your code
}
while(Console.ReadKey().KeyChar == 'Y');

Related

Run if statement block if either one of the conditionals are true [closed]

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 last year.
Improve this question
I need to write an if statement block that will run if the value entered is less than $5.65 or greater than 50. How can I do this?
using System;
using static System.Console;
namespace HomeWork1
{
internal class Program
{
static void Main(string[] args)
{
WriteLine ("What is your hourly pay rate");
double rate;
string input;
input = ReadLine();
rate =Convert.ToDouble(input);
WriteLine("Your hourly pay rate {0}", rate);
if (rate < 5.65 )
{
Console.WriteLine("Error entering your pay rate");
}
}
}
}
}
Use the or operator || to make this work. The or operator || will execute the if block if either one of the conditions are true.
if (rate < 5.65 || rate > 50)
{
Console.WriteLine("Error entering your pay rate");
}

Hi there I want to know how this kind of conditional statement means? if (i == 0) lowest = highest = input; [closed]

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 2 years ago.
Improve this question
Hi there I want to know how this kind of conditional statement means?
if (i == 0)
{
lowest = highest = input;
}
When you come across questions like this, i would recommend that you test it yourself. For instance, this can be tested in a simple console app to see what happens
class Program
{
public static void Main(string[] args)
{
int lowest = 1;
int input = 2;
int highest = 3;
Console.WriteLine("Before equality operator");
Console.WriteLine($"lowest: {lowest}");
Console.WriteLine($"highest: {highest}");
Console.WriteLine($"input: {input}");
int i = 0;
if (i == 0) lowest = highest = input;
Console.WriteLine("After equality operator");
Console.WriteLine($"lowest: {lowest}");
Console.WriteLine($"highest: {highest}");
Console.WriteLine($"input: {input}");
}
}
Output:
Before equality operator
lowest: 1
highest: 3
input: 2
After equality operator
lowest: 2
highest: 2
input: 2

Write program which count sum of numbers divided by 4 [closed]

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 3 years ago.
Improve this question
I need to write a program which count sum of numbers divided by 4. I'm really beginner in C#.
Could you lead me to solve this problem?
I write something like this but I don't know what next and there is one problem because I put only two numbers but numbers could be a lot of.
Console.WriteLine("number a");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("number b");
int b = int.Parse(Console.ReadLine());
int sum = a + b;
int result = sum / 4 ;
Console.WriteLine ( "result is="+ result ) ;
use
double sum = Console.ReadLine().Split().Sum(x => int.Parse(x)) / 4.0;
Than you can enter any space separated array like
1 3 5 7

C# if statement within a range [closed]

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 6 years ago.
Improve this question
I need my if statement to return an image if it is within a range. the current code does not work
if (Int32.Parse(Domain_OSUMC_IT_CHECKBOX.Text.Trim()) == 1)
{
Domain_green_Check.Visible = true;
}
else if (Int32.Parse(XP_OSUWMC_IT_LBL.Text.Trim()) >= 1 && <=.9)
{
Domain_green_Check.Visible = true;
This is where im having the trouble
else if (Int32.Parse(XP_OSUWMC_IT_LBL.Text.Trim()) >= 1 && <=.9)
I need to make the image domain_green_check visible if another label Domain_OSUMC_IT_CHCEKBOX is between the values of .9 and 1
You need to fix your syntax and conert the string to decimal
decimal val = decimal.Parse(XP_OSUWMC_IT_LBL.Text.Trim());
else if (val > .9 && val < 1) //though this condition makes nosense since it will never evaluate to TRUE

For int i = value [closed]

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 9 years ago.
Improve this question
I am trying to create some code that search for a value .
As of now the code looks like :
private void button4_Click(object sender, EventArgs e)
{
uint randBuff = DLL.Extension.ReadUInt32(0x0154d6e4);
for (int i = 0; i < 144705; i++)
{
randBuff = (randBuff + 4);
listBox1.Items.Add(randBuff.ToString("x8"));
}
}
The value I search is 144705 . The idea is to stop searching for the value when randBuff =144705 . Can this be done with a loop or is there any other way to do it ?
If I understand your question right, then this is more appropriate of a loop:
while (randBuff < 144705)
{
listBox1.Items.Add(randBuff.ToString("x8"));
randBuff += 4;
}
Basically, as long randBuff is less than the target value of 144705, add the value to the list box and increase the value by 4.

Categories

Resources