Jump to content

Loops and Do-While statements

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
vbstudent

vbstudent

    Newbie

  • Members
  • Pip
  • 9 posts
Hello all,

I have one assignment left to finish my VB course. I have to finish it by this week or I will have to pay a late fine.

This is the program:
Write a program to run two separate threads printing numbers (or words) in ascending and descending orders. The numbers (or words) should be given by the user.

Now will I have to use a stack, or a queue, or something like that? Or would I only use Loops and Do-whiles? And can somebody jump-start me with a little bit of code?

Thanks

#2
Grimling

Grimling

    Newbie

  • Members
  • PipPip
  • 13 posts
Do you mean that you asks the user for the words, and then the two threads show the words? Thread one in ascending order and thread two in descending order? Can you also specify what kind of program you want to make? A console-program or one with a graphical user interface?

Floris

#3
vbstudent

vbstudent

    Newbie

  • Members
  • Pip
  • 9 posts
Oh I'm sorry I was out all day yesterday and I realized that I forgot to add that. That is correct. It's a console application in Visual Basic 2008 Express. The program must ask the user for either a word or a starting number and an ending number. They both have to be printed in both ascending and descending order. Thank you for taking the time to help!

#4
Grimling

Grimling

    Newbie

  • Members
  • PipPip
  • 13 posts
I don't think I understand all you said, but I think you mean something like this:

        Dim inputs As New List(Of String)

        Dim answer As String

        Do

            Console.WriteLine("Add a word to the list.")

            inputs.Add(Console.ReadLine())

            Console.WriteLine("Do you want to add another word? (y/Y = yes)")

            answer = Console.ReadLine()

        Loop Until (answer <> "Y" And answer <> "y")

        inputs.Sort()

        Console.WriteLine("Ascending order:")

        For Each str As String In inputs

            Console.WriteLine(str)

        Next

        Console.WriteLine("Descending order:")

        For i As Integer = inputs.Count - 1 To 0 Step -1

            Console.WriteLine(inputs.ElementAt(i))

        Next

        Console.ReadLine()

If it isn't, please tell me and give some more information.

Floris

#5
vbstudent

vbstudent

    Newbie

  • Members
  • Pip
  • 9 posts
Hmm, tis could work, thamk you very much. However, there is a possibility that the teacher wants it to print every letter seerately and on seperate lines(If that makes sense?). Like i would input the word "thanks" and it would give me back:
Ascending:
T
h
a
n
k
s

Descending:
s
k
n
a
h
T

I have to wait for the teacher to get back to me on that one. But still this is much appreciated. I learned some new coding from this! If I could ever be of help to you, send me a pm!

#6
Grimling

Grimling

    Newbie

  • Members
  • PipPip
  • 13 posts
No problem :).
But one question: can I ask you what course you follow? Haven't you seen these types of loops? If not, you can ask your teacher for more explanation.
If you want your program working on the way you just explained, I suggest you to use this kind of code. Again, it's basic. You should add some extras, like giving the user the possibility to fill in multiple words.
        Dim input As String
        Console.WriteLine("Give me a word, please.")
        input = Console.ReadLine()
        Console.WriteLine("ascending:")
        For i As Integer = 0 To input.Length - 1
            Console.WriteLine(input.Chars(i))
        Next
        Console.WriteLine("descending:")
        For i As Integer = input.Length - 1 To 0 Step -1
            Console.WriteLine(input.Chars(i))
        Next
        Console.ReadLine()


#7
vbstudent

vbstudent

    Newbie

  • Members
  • Pip
  • 9 posts
Thanks that's great. Yeah i don't mind its from an online school and its called Programming: Visual Basic.NET and java. I'm not taking tha Java part yet though. But this course realy doesn't explain stuff too well, it wasn't good for beginners, and the teacher wasn't too helpful and took a long time to get back. But yeah its a really hard course for beginners not wanting to sound lazy here(Which this probably does). There was about 45 students that began the course, and only about 4 got to the end, including(barely) me. Thanks again for the help! Greatly appreciated!

#8
Grimling

Grimling

    Newbie

  • Members
  • PipPip
  • 13 posts
You're welcome. Maybe it's a good idea to look for tutorials on google. I'm not saying I'm good at programming, but I've learned it by doing that.
Floris