Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I am in the process of making a Console app which will ask trivial questions (ATV specs mostly). Anyways, I've done a little work with the Random object, and was wondering how one would possibly going about using it so that the program will ask the questions in a random order. Thanks.

Dodge

Grab Life By The Horns

  • *Gurus*
Posted
Imports System

Dim sQuestions() As String = {"Question 1", "Question 2", "Question 3"}

Dim r As New Random(DateTime.Now.Ticks)

Dim nElement As Decimal = r.Sample * sQuestions.GetUpperBound(0)

Console.WriteLine(sQuestions(Decimal.ToInt32(nElement)).ToString)

Posted

Crazed Lunatic, I don't quite understand the sample. :( Also, the complier didn't like the r.sample line.

 

My code basically looks like this:

 

Console.WriteLine("SP4-What size pilot jet does a Sportsman 400 have?")
       answer = Console.ReadLine
       If answer = 40 Then
           Points = Points + 1
'Points is a counter
           Console.WriteLine("Correct! Total Points: " & Points) 
           Console.ReadLine()
       Else
           Console.WriteLine("Incorrect! Answer is: 40")
           Console.WriteLine("Total Points: " & Points)
           Console.ReadLine()
       End If

 

I put the Console.Readline's in there so that the application would pause, and wait for the user to press a key to continue. I'm not sure if there's a better way to do that though.

 

Back to the subject, I'm not sure like if I should put each question and it's answer logic in separate subs, or what the deal is with it. Thank you.

Dodge

Grab Life By The Horns

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...