Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Help with writing programs in C#, don't know if I should use if, while, or else statements?

I have two problems below:

1.) Write a C# program that counts the number of integers greater than 100 entered by the user. The user terminates the input with a negative number.

2.) Write a C# program that finds the minimum of the nonnegative numbers entered by the user. Ask the user to input the quantity of numbers to be entered first.

I have no idea where to start and my teachers just expect everyone to know how to solve these problems. Please if someone could explain how to solve these problems and then I will spend time trying to understand them so that it "clicks" in my brain and I get the logic.

1 Answer

Relevance
  • Anonymous
    7 years ago
    Favorite Answer

    It sounds like for the first problem your teacher is wanting you to use a for loop nested inside of a while loop

    While I don't believe it would help you if I just "gave" you the code, I will give you an idea of what I mean.

    While (input is greater than or equal to zero)

    {

    for(input greater than 100)

    {

    add input to a collection which holds all inputs greater than 100

    }

    }

    count the number of inputs in the collection and output that to some textbox, messagebox, or line in the console.

    As for the second program, I believe your teacher wants you to make use of an array whose size is fixed to hold the number of values chosen by the user, and after all values are put into the array do something to the effect of:

    int i= first value in the array (index 0)

    for(value in the array greater than or equal to zero)

    {

    if(current value in the array is greater than i)

    {

    i = value

    }

    }

    in that way "i" will end up being the least non negative value in the array. Afterwards you simply output "i" to wherever the teacher wants it (such as a textbox or messagebox)

Still have questions? Get your answers by asking now.