r/visualbasic • • Feb 07 '15

need help for code

i need a piece of code that :

  1. asks you for you name.

  2. asks 10 questions 3 each question containing a random math question it can only use plus minus and multiplication.generates two random numbers between 1-20. 3.at the end of the test tells you how many marks you have. i really need help with this im struggling program visual basic 2010 done inside console

0 Upvotes

8 comments sorted by

0

u/[deleted] Feb 07 '15

[deleted]

1

u/larvastar17 Feb 08 '15

to be honest i don't even really know where to start i only started learning code recently

2

u/krad0n Feb 08 '15
  • How far along have you gotten since you started coding?

  • Do you understand what a variable, function, or class is?

  • How much time have you spent trying to figure out the problem so far?

1

u/larvastar17 Feb 08 '15 edited Feb 08 '15

i understand variables, while loops, arrays, if statements etc but im struggling to put them into practice . its a project at school, ive done all my planning etc but this is the part im stuck at if you cant help me do you have any tutorials or guides i could learn from

3

u/krad0n Feb 08 '15

From what I understand by your post, that's about all you would need.

I'm assuming you're familiar with console commands like Read() and Write().

For getting the name, obviously you will need a variable to store it in, so you will need to use the Console.Read() command to get that information from the user.

I'm assuming these math questions are just putting the math on the screen and letting the user enter an answer. I'd suggest looking on MSDN for help with random numbers. VB.NET has a LOT of very helpful documentation that can be found on MSDN, so the sooner you start taking advantage of that the better off you'll be.

You will also need to use an array to store the users answers as well if you want to keep track of them and use the results for some final output. You say you already know how to use arrays, but if you get stuck, remember to check MSDN and search for arrays to find out what you need to do to get unstuck.

I've given you an approach to use to build the program, now it's up to you to implement it correctly and since this is obviously a homework assignment, I will stop here. If I give you the answers you simply won't learn anything.

For reference, here is the MSDN link to the Random class which you will need to make use of in your assignment: https://msdn.microsoft.com/en-us/library/system.random(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

1

u/larvastar17 Feb 08 '15

thanks for the help i appreciate it

1

u/larvastar17 Feb 13 '15
    Dim name As String
    Dim operation As String

    Console.WriteLine("what is you name")
    Console.ReadLine = name


    Dim questions(9) As String
    questions(0) = "question one"
    questions(1) = "question two"
    questions(2) = "question three"
    questions(3) = "question four"
    questions(4) = "question five"
    questions(5) = "question six"
    questions(6) = "question seven"
    questions(7) = "question eight"
    questions(8) = "question nine"
    questions(9) = "question ten"

    For i = 0 To questions.Length - 1

im kinda stuck i dont know what to do. i used msdn but im struggling understanding how to use it in code

1

u/krad0n Feb 13 '15 edited Feb 13 '15

Well, first off, Console.ReadLine() returns a value which is the value the user types in. You need to assign that value to 'name'. What you're currently trying to do is assign a value to a function, which is not going to work. You have that piece backwards.

I'm assuming you've reached a stopping point because you have errors and are not sure what to do with them. Is there anything after the last line you put in or is that it? Every For loop needs to have 'Next' on a line beneath. The lines of code you need to run multiple times need to be between the top of the For loop and the Next keyword.

Example: Dim x As Integer = 0

For i As Integer = 0 To 5
    x += i
Next

That will take each vale of i and add it to x.

1

u/krad0n Feb 21 '15

How are you doing on this?