locked
needs help RRS feed

  • Question

  • design a pseudocode that asks the user for two numbers, and then sends these two numbers as arguments to four arithmetic functions: addition, multiplication, division, and modulus (the remainder after dividing one number by the other). The functions should return the values to the calling module, where they're displayed.
    Sunday, April 5, 2015 7:53 PM

Answers

  • ok how do i put that in a pseudocode? because im stuck on forming one for this activity

    That's already pseudocode.    It is simply statements in plain English (or nearly so) that look a bit like a programming language but describe what you need to do rather than setting out the actual code that you will use.

    You develop the pseudocode by making the statements more and more detailed - such as expanding "design addition function" into
      Get First Variable
      Get Second variable
      Return the sum

    until you have something that can be converted directly into valid code.


    • Edited by Acamar Monday, April 13, 2015 9:52 PM fmt
    • Marked as answer by Youjun Tang Monday, April 20, 2015 9:22 AM
    Monday, April 13, 2015 9:52 PM
  • A few basics

    Passing integers

        Public Function DemoAdding(
            ByVal Value1 As Integer,
            ByVal Value2 As Integer) As Integer
    
            Return Value1 + Value2
    
        End Function
        Public Function DemoDivide(
            ByVal Value1 As Integer,
            ByVal Value2 As Integer) As Integer
    
            Return Value1 \ Value2
    
        End Function

    Passing strings

        Public Function DemoAdding(
            ByVal Value1 As String,
            ByVal Value2 As String) As Integer
    
            Dim Int1 As Integer = 0
            Dim Int2 As Integer = 0
    
            If Integer.TryParse(Value1, Int1) AndAlso Integer.TryParse(Value2, Int2) Then
                Return Int1 + Int2
            End If
        End Function
    Best not to use strings here as we then need to decide how to handle values that are not convertible to integer.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by Youjun Tang Monday, April 20, 2015 9:22 AM
    Sunday, April 5, 2015 8:07 PM

All replies

  • A few basics

    Passing integers

        Public Function DemoAdding(
            ByVal Value1 As Integer,
            ByVal Value2 As Integer) As Integer
    
            Return Value1 + Value2
    
        End Function
        Public Function DemoDivide(
            ByVal Value1 As Integer,
            ByVal Value2 As Integer) As Integer
    
            Return Value1 \ Value2
    
        End Function

    Passing strings

        Public Function DemoAdding(
            ByVal Value1 As String,
            ByVal Value2 As String) As Integer
    
            Dim Int1 As Integer = 0
            Dim Int2 As Integer = 0
    
            If Integer.TryParse(Value1, Int1) AndAlso Integer.TryParse(Value2, Int2) Then
                Return Int1 + Int2
            End If
        End Function
    Best not to use strings here as we then need to decide how to handle values that are not convertible to integer.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by Youjun Tang Monday, April 20, 2015 9:22 AM
    Sunday, April 5, 2015 8:07 PM
  • design a pseudocode that asks the user for two numbers, and then sends these two numbers as arguments to four arithmetic functions: addition, multiplication, division, and modulus (the remainder after dividing one number by the other). The functions should return the values to the calling module, where they're displayed.

    Is this homework?
    Sunday, April 5, 2015 8:29 PM
  • Are you expecting someone to do your homework for you?

    Solitaire

    Sunday, April 5, 2015 11:20 PM
  • Are you expecting someone to do your homework for you?

    Solitaire


    My guess is that it's a fishing expedition ... toss a line out and come back later to see if anything is on the hook.

    Still lost in code, just at a little higher level.

    :-)

    Sunday, April 5, 2015 11:34 PM
  • design addition function
    design multiplication function
    design division function
    design modulus function

    Get first number, assign to variable
    Get second number, assign to a different variable

    Pass the two variables to each function and display the result along with text to describe which function is being shown
    Display message for user to press a key
    Wait for keypress
    End program

    There you go


    Monday, April 6, 2015 2:38 AM
  • I also like the OP's topic, when I look at "Related Threads", I see:

    need help
    Needs Help
    Need help...
    Need help !!!!
    Need help

    • Proposed as answer by Cor Ligthert Monday, April 6, 2015 8:01 AM
    Monday, April 6, 2015 2:43 AM
  • design a pseudocode that asks the user for two numbers, and then sends these two numbers as arguments to four arithmetic functions: addition, multiplication, division, and modulus (the remainder after dividing one number by the other). The functions should return the values to the calling module, where they're displayed.

    I don't know any pseudocode forums for you to move your question to.

    Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading.


    La vida loca

    Monday, April 6, 2015 5:26 AM
  • ok how do i put that in a pseudocode? because im stuck on forming one for this activity
    Monday, April 13, 2015 9:20 PM
  • ok how do i put that in a pseudocode? because im stuck on forming one for this activity

    That's already pseudocode.    It is simply statements in plain English (or nearly so) that look a bit like a programming language but describe what you need to do rather than setting out the actual code that you will use.

    You develop the pseudocode by making the statements more and more detailed - such as expanding "design addition function" into
      Get First Variable
      Get Second variable
      Return the sum

    until you have something that can be converted directly into valid code.


    • Edited by Acamar Monday, April 13, 2015 9:52 PM fmt
    • Marked as answer by Youjun Tang Monday, April 20, 2015 9:22 AM
    Monday, April 13, 2015 9:52 PM
  • here is the pseudocode I wrote:

      

    // Program Name: Number Functions
    // Purpose: Performs four arithmetic operation on two numbers
    // Author Name: Zinah Ghazi
    // Date last modified: 04-01-2017

    Start
       // Declare variables
       Declare Numeric num1, num2 // two numbers entered by user
       Declare Numeric sum // sum of two numbers
       Declare Numeric prod // product of two numbers
       Declare Numeric quotient // result of dividing two numbers
       Declare Numeric mod // the modulus of two numbers

       // Display program heading, ask for two numbers
       Display "This program performs arithmetic operations on the two numbers you enter."
       Display "Please enter the first number: "
       Input num1
       Display "Please enter the second number: "
       Input num2

       // Call the four models, display the results
       sum = addition (num1, num2)
       Display "The sum of the two numbers is: "+ sum
       prod = multiplication (num1, num2)
       Display "The product of the two numbers is: "+ prod
       quotient = division (num1, num2)
       Display "The quotient of the two numbers is: "+ quotient

       // Thank the user and end the program 
       Display “Thank you!”
    stop

    Function Numeric addition (Numeric n1, Numeric n2)
       // Declare variables
       Declare Numeric result
       result = n1 + n2
       Return result
    End function 

    Function Numeric multiplication (Numeric n1, Numeric n2)
       // Declare variables
       Declare Numeric result
       result = n1 * n2
       Return result
    End function 

    Function Numeric division (Numeric n1, Numeric n2)
          // Declare variables
          Declare Numeric result
          result = n1 /n2
          Return result
    End function 

    Function Numeric modulus (Numeric n1, Numeric n2)
          // Declare variables
          Declare Numeric result
          result = n1 % n2
          Return result
    End function 

    End program

    enjoy!

    Zinah

    Wednesday, April 19, 2017 4:01 AM