Have a program I am writing for class using the pseudocode given. I have written it in a flowchart program successfully, but cannot get it to work properly in VB. It is supposed to show the C for Celsius and F for Fahrenheit, and list the matching equivalents below up to 100 for Celsius when the loop will end. It shows the C and F in but no numbers...I am stumped. I have attached the zipped file. Thanks!

Dani AI

Generated

A few focused points that build on ’s diagnosis: the program prints the headers but no numbers because the loop body never executes the increment/print — the If intC > 100 is reversed so intC stays 0 forever. Also, placing Console.Read before the loop will pause output immediately, so the pause belongs after the loop. Two robust ways to fix this are (a) remove the unnecessary If and let the loop condition control termination, or (b) use a For loop so the increment is explicit and less error-prone.

A compact, safe pattern that avoids those pitfalls and keeps columns aligned:

Sub Main()
    Console.WriteLine("C   F")
    For c As Integer = 0 To 100 Step 10
        Dim f As Integer = CInt(c * 9.0 / 5.0 + 32.0)
        Console.WriteLine("{0,3} {1,4}", c, f)
    Next
    Console.ReadKey()
End Sub

Extra troubleshooting and good-practice notes (complements ’s debugging tips): turn on Option Strict On to catch implicit conversions; prefer 9.0 / 5.0 (or explicit casts) so the temperature formula uses floating-point math before converting to Integer; avoid VB’s integer-division operator (\) unless integer division is intended. Use formatted output (composite format or PadLeft/PadRight) to keep columns stable. When translating from a flowchart tool like Raptor, double-check whether a loop is “repeat-until” (post-test) versus “while” (pre-test)—that difference often causes off-by-one or placement-of-increment bugs. Finally, stepping through the code in the debugger or adding temporary Console.WriteLine traces for intC and intF will quickly show where execution diverges from the intended flow.

Recommended Answers

All 2 Replies

It's best to post your code, as some people don't want to download unknown files to their computer.

Your original code:

Module Module1
    Sub Main()
        'Declarations
        Dim intC As Integer = 0
        Dim intF As Integer = 0
        'Display 
        Console.WriteLine("C                 F")
        Console.Read()

        Do
            If intC > 100 Then
                intF = CInt((9 / 5 * intC + 32))
                Console.WriteLine(intC & "           " & intF)
                intC = intC + 10
            End If
        Loop Until (intC > 100)
    End Sub
End Module

Issues:

You have If intC > 100. This will never occur, because all of your calculations are inside the if statement and intC is 0. This if statement is unnecessary because the loop condition will do everything you need. If you choose to keep it, change it to If intC < 100. Right now you have an infinite loop, because "intC" is always < 100.

You have Console.Read before the loop. This will wait for input. You may want to put this after the loop, if your intent is to keep the window open until the user presses a key.

Note: You can use "Console.WriteLine" statements to help you debug your program. See below for example.

This is your original code with "Console.WriteLine" statements inserted for debugging purposes:

Module Module1
    Sub Main()
        'Declarations
        Dim intC As Integer = 0
        Dim intF As Integer = 0
        'Display 
        Console.WriteLine("C                 F")

        'used for debugging
        Console.WriteLine("Before console.read")

        Console.Read()

        Do
            'used for debugging
            Console.WriteLine("in loop. before if. intC=" & intC)

            If intC > 100 Then
                'used for debugging
                Console.WriteLine("in if. intC=" & intC)

                intF = CInt((9 / 5 * intC + 32))
                Console.WriteLine(intC & "           " & intF)
                intC = intC + 10
            End If

            'used for debugging
            Console.WriteLine("after if. intC=" & intC)

        Loop Until (intC > 100)
    End Sub
End Module

Thanks CGeier, I will try it in the morning. It is completely different writing it in VB than in Raptor(the flowchart program we have to use as well.) I'll keep you updated! Thanks again. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.