Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Console Problems (http://www.programmingforums.org/showthread.php?t=11370)

bigguy Sep 22nd, 2006 11:21 AM

Console Problems
 
:

Module Module1

    Sub Main()
        Console.Title = "Speech Calculator Demonstration"
        Console.WriteLine("Thank you for paying attention to my Speech Calculator Demonstration", vbCrLf, "for Mrs.McCurley's Class. I hope you get something out of my speech")
        Console.WriteLine("Please choose the type of problem you want to calculate")
        Console.WriteLine("-------------------------------------------------------")
        Console.WriteLine("1. Addition")
        Console.WriteLine("2. Subtraction")
        Console.WriteLine("3. Multiplication")
        Console.WriteLine("4. Division")
        Console.WriteLine("5. Exit")
        Console.WriteLine("-------------------------------------------------------")
        If Console.ReadLine = "1" Then
            Call add1()
        End If
        If Console.ReadLine = "2" Then
            Call sub1()
        End If
        If Console.ReadLine = "3" Then
            Call mul1()
        End If
        If Console.ReadLine = "4" Then
            Call div1()
        End If
        If Console.ReadLine = "5" Then
            Exit Sub
        End If
    End Sub

    Sub again()
        Console.Title = "Speech Calcualtor Demonstration"
        Console.WriteLine("Thank you for paying attention to my Speech Calculator Demonstration", vbCrLf, "for Mrs.McCurley's Class. I hope you get something out of my speech")
        Console.WriteLine("Please choose the type of problem you want to calculate")
        Console.WriteLine("-------------------------------------------------------")
        Console.WriteLine("1. Addition")
        Console.WriteLine("2. Subtraction")
        Console.WriteLine("3. Multiplication")
        Console.WriteLine("4. Division")
        Console.WriteLine("-------------------------------------------------------")
    End Sub

    Sub add1()
        Dim number1 As Double
        Dim number2 As Double
        Dim result As String
        Console.WriteLine("Please enter your first number")
        number1 = Console.ReadLine()
        Console.WriteLine("Please enter your second number")
        number2 = Console.ReadLine()
        result = number1 + number2
        Console.WriteLine("The answer to " & number1 & "+" & number2 & "=" & result)
        Console.WriteLine("Would you like to calculate another problem?")
        If Console.ReadLine = "Yes" Then
            Call Main()
        Else
            Exit Sub
        End If
    End Sub

    Sub sub1()
        Dim number1 As Double
        Dim number2 As Double
        Dim result As String
        Console.WriteLine("Please enter your first number")
        number1 = Console.ReadLine()
        Console.WriteLine("Please enter your second number")
        number2 = Console.ReadLine()
        result = number1 - number2
        Console.WriteLine("The answer to " & number1 & "-" & number2 & "=" & result)
        Console.WriteLine("Would you like to calculate another problem?")
        Console.ReadLine()
        If Console.ReadLine = "Yes" Then
            Call Main()
        Else
            Exit Sub
        End If
    End Sub

    Sub mul1()
        Dim number1 As Double
        Dim number2 As Double
        Dim result As String
        Console.WriteLine("Please enter your first number")
        number1 = Console.ReadLine()
        Console.WriteLine("Please enter your second number")
        number2 = Console.ReadLine()
        result = number1 * number2
        Console.WriteLine("The answer to " & number1 & "*" & number2 & "=" & result)
        Console.WriteLine("Would you like to calculate another problem?")
        Console.ReadLine()
        If Console.ReadLine = "Yes" Then
            Call Main()
        Else
            Exit Sub
        End If
    End Sub

    Sub div1()
        Dim number1 As Double
        Dim number2 As Double
        Dim result As String
        Console.WriteLine("Please enter your first number")
        number1 = Console.ReadLine()
        Console.WriteLine("Please enter your second number")
        number2 = Console.ReadLine()
        result = number1 / number2
        Console.WriteLine("The answer to " & number1 & "/" & number2 & "=" & result)
        Console.WriteLine("Would you like to calculate another problem?")
        Console.ReadLine()
        If Console.ReadLine = "Yes" Then
            Call Main()
        Else
            Exit Sub
        End If
    End Sub
End Module


The problem I am having is this. When I choose my type of problem instead of having to enter the # once I have to enter it twice before it calls the Sub. Then when I want to do another problem and I type yes, it wont go, so I keep typign yes and after 4 times it exits the program. I am so confused since I dont even have that many console.readline's in the sub's. Please help

DaWei Sep 22nd, 2006 11:32 AM

I don't do .NET; that said, what do you suppose would happen if everyone that wanted to study the universe began with a call to "big bang".

MBirchmeier Sep 22nd, 2006 11:49 AM

Quote:

Originally Posted by DaWei (Post 114758)
I don't do .NET; that said, what do you suppose would happen if everyone that wanted to study the universe began with a call to "big bang".

It seems like you have a habit of leaving your pearls of wisdom buried in the mud, one might not always be able to see what you're talking about, but once one gets their hands sufficiently dirty it is easy enough to find.

-MBirchmeier

big_k105 Sep 22nd, 2006 12:43 PM

:

  1. Module Module1
  2.  
  3.     Sub Main()
  4.         Console.Title = "Speech Calculator Demonstration"
  5.         Console.WriteLine("Thank you for paying attention to my Speech Calculator Demonstration", vbCrLf, "for Mrs.McCurley's Class. I hope you get something out of my speech")
  6.         Console.WriteLine("Please choose the type of problem you want to calculate")
  7.         Console.WriteLine("-------------------------------------------------------")
  8.         Console.WriteLine("1. Addition")
  9.         Console.WriteLine("2. Subtraction")
  10.         Console.WriteLine("3. Multiplication")
  11.         Console.WriteLine("4. Division")
  12.         Console.WriteLine("5. Exit")
  13.         Console.WriteLine("-------------------------------------------------------")
  14.         Dim choice As String
  15.         choice = Console.ReadLine()
  16.         If choice = "1" Then
  17.             Call add1()
  18.         ElseIf choice = "2" Then
  19.             Call sub1()
  20.         ElseIf choice = "3" Then
  21.             Call mul1()
  22.         ElseIf choice = "4" Then
  23.             Call div1()
  24.         ElseIf choice = "5" Then
  25.             Exit Sub
  26.         End If
  27.     End Sub
  28.  
  29.     Sub again()
  30.         Console.Title = "Speech Calcualtor Demonstration"
  31.         Console.WriteLine("Thank you for paying attention to my Speech Calculator Demonstration", vbCrLf, "for Mrs.McCurley's Class. I hope you get something out of my speech")
  32.         Console.WriteLine("Please choose the type of problem you want to calculate")
  33.         Console.WriteLine("-------------------------------------------------------")
  34.         Console.WriteLine("1. Addition")
  35.         Console.WriteLine("2. Subtraction")
  36.         Console.WriteLine("3. Multiplication")
  37.         Console.WriteLine("4. Division")
  38.         Console.WriteLine("-------------------------------------------------------")
  39.     End Sub
  40.  
  41.     Sub add1()
  42.         Dim number1 As Double
  43.         Dim number2 As Double
  44.         Dim result As String
  45.         Console.WriteLine("Please enter your first number")
  46.         number1 = Console.ReadLine()
  47.         Console.WriteLine("Please enter your second number")
  48.         number2 = Console.ReadLine()
  49.         result = number1 + number2
  50.         Console.WriteLine("The answer to " & number1 & "+" & number2 & "=" & result)
  51.         Console.WriteLine("Would you like to calculate another problem?")
  52.         Dim choice As String
  53.         choice = Console.ReadLine()
  54.         If choice = "Yes" Then
  55.             Call Main()
  56.         Else
  57.             Exit Sub
  58.         End If
  59.     End Sub
  60.  
  61.     Sub sub1()
  62.         Dim number1 As Double
  63.         Dim number2 As Double
  64.         Dim result As String
  65.         Console.WriteLine("Please enter your first number")
  66.         number1 = Console.ReadLine()
  67.         Console.WriteLine("Please enter your second number")
  68.         number2 = Console.ReadLine()
  69.         result = number1 - number2
  70.         Console.WriteLine("The answer to " & number1 & "-" & number2 & "=" & result)
  71.         Console.WriteLine("Would you like to calculate another problem?")
  72.         Dim choice As String
  73.         choice = Console.ReadLine()
  74.         If choice = "Yes" Then
  75.             Call Main()
  76.         Else
  77.             Exit Sub
  78.         End If
  79.     End Sub
  80.  
  81.     Sub mul1()
  82.         Dim number1 As Double
  83.         Dim number2 As Double
  84.         Dim result As String
  85.         Console.WriteLine("Please enter your first number")
  86.         number1 = Console.ReadLine()
  87.         Console.WriteLine("Please enter your second number")
  88.         number2 = Console.ReadLine()
  89.         result = number1 * number2
  90.         Console.WriteLine("The answer to " & number1 & "*" & number2 & "=" & result)
  91.         Console.WriteLine("Would you like to calculate another problem?")
  92.         Dim choice As String
  93.         choice = Console.ReadLine()
  94.         If choice = "Yes" Then
  95.             Call Main()
  96.         Else
  97.             Exit Sub
  98.         End If
  99.     End Sub
  100.  
  101.     Sub div1()
  102.         Dim number1 As Double
  103.         Dim number2 As Double
  104.         Dim result As String
  105.         Console.WriteLine("Please enter your first number")
  106.         number1 = Console.ReadLine()
  107.         Console.WriteLine("Please enter your second number")
  108.         number2 = Console.ReadLine()
  109.         result = number1 / number2
  110.         Console.WriteLine("The answer to " & number1 & "/" & number2 & "=" & result)
  111.         Console.WriteLine("Would you like to calculate another problem?")
  112.         Dim choice As String
  113.         choice = Console.ReadLine()
  114.         If choice = "Yes" Then
  115.             Call Main()
  116.         Else
  117.             Exit Sub
  118.         End If
  119.     End Sub
  120.  
  121. End Module

Above is the way I took your code and changed it. What I ended up doing is removing all the console.readline's you had inside of the if statements and put one before the if and and put the input into a variable instead and then checking the variable in the if. After testing it. It looks like it worked fine.

After looking through your code, I couldn't figure out where the again() sub was being used. Seems like of pointless to have it there.

DaWei Sep 22nd, 2006 3:36 PM

Quote:

have a habit of leaving your pearls of wisdom buried in the mud
Sometimes I do. Sometimes I submit full-blown copy-and-paste solutions or long-drawn-out explications and discussions. Feed a man a fish, he'll eat for a day. Point him to the way out of the cave-in, and dirty fingernails or not, he prolly won't be digging under shaky cutbanks again.

bigguy Sep 24th, 2006 12:34 PM

Thanks yall
 
Thanks big_k, the again was at the start where Call Main is now, I looked over my code and relized agaim and Main are the same code, before I had it call again and then changed it to call Main, thkans though.

And yes Dawei, I was a bit confused at your first post, but thanks for trying to help. Maybe when I'm older I can give advice like that. lol


All times are GMT -5. The time now is 1:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC