Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have Programming in Basic in High School and was tasked with a project in which I was to make a program that says hello to the teacher as well as give a paragraph describing why programming is valuable in today's time.

My initial idea was to make a program that greets and asks the teacher a question on whether they want to know why programming is valuable. When the console asks the question there will be two options: Yes or No. Each having their own text output.

Module Module1

    Sub Main()
        REM Test
        Dim Yes As String
        Dim No As String
        Console.WriteLine("Hello, Would you like to know why programming is valuable? Yes or No")
        Yes = Console.ReadLine
        No = Console.ReadLine
        If Console.ReadLine = Yes Then
            Console.WriteLine("Well...1")
        End If
        If Console.ReadLine = No Then
            Console.WriteLine("Well...2")
        End If

    End Sub

End Module


This works but I have to put "Yes" on the console three times before the "Well...1" pops up and when I test it out with "No", "Well...1" pops up instead of "Well...2". Sometimes "Well...2" pops up but it's rare.

What I have tried:

I've tried everything suggested to me in other forums but no success. So far, this is the code I had the most success with but still get a few flaws.
Posted
Updated 7-Sep-16 16:40pm

you're doing a lot of console.readline(s) there ... are you sure you need that many ? how about something like (using one variable to hold the answer, instead of one for yes and no)

VB
Dim answer As String
Console.WriteLine("Hello, Would you like to know why programming is valuable? Yes or No")
StringComparison comparison = StringComparison.OrdinalIgnoreCase 
answer = Console.ReadLine
If answer.Contains("yes", comparison) Then
    Console.WriteLine("Well...1")
End If
If answer.Contains("no"), comparison Then
    Console.WriteLine("Well...2")
End If


note that (if Ive done this correctly), it doesnt matter if they enter 'YES' or 'yES' or 'Yes it does' - the StringComparison and the contains will handle it - you can then do more work on 'answer' in your If/End-If checks

does that make life easier ?
 
Share this answer
 
Quote:
This works but I have to put "Yes" on the console three times before the "Well...1" pops up and when I test it out with "No", "Well...1" pops up instead of "Well...2". Sometimes "Well...2" pops up but it's rare.
This is exactly what you asked your program to do.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900