Question

Must be written in VBA Create a program called moremath to request a whole number, n,...

Must be written in VBA

Create a program called moremath to request a whole number, n, from 1 to 30, and one of the letters S or P. Then, depending upon whether S or P was selected, calculate the sum or product of the numbers from 1 to n.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dim n As Integer

Private Sub moremath_Click()
    Dim choices(2) As String
    Dim i As Integer
    Dim index As Integer
  
    choices(1) = "S"
    choices(2) = "P"
    'Generating whole number
    n = Int((30 - 1 + 1) * Rnd + 1)
    Cells(2, 1) = n
    'Generating index value between 1 and 2
    index = Int((2 - 1 + 1) * Rnd + 1)
    'Selecting choice based on generated index
    choice = choices(index)
    Cells(2, 2) = choice

    If choice = "S" Then 'If choice is s then calls function sum()
        Call sum
    ElseIf choice = "P" Then 'If choice is p then calls function product()
        Call product
    End If
End Sub

Private Function sum()
    Dim i As Integer
    Dim s As Double
      
    'Calculating sum and then displaying in message box
    s = 0
    For i = 1 To n
        s = s + i
    Next i
    Cells(2, 3) = s
  
End Function

Private Function product()
    Dim i As Integer
    Dim p As Double
      
    'Calculating product and then displaying in message box
    p = 1
    For i = 1 To n
        p = p * i
    Next i
    Cells(2, 3) = p
End Function

Link for the file: https://drive.google.com/open?id=0B-wCyuB1jOs7OHUzdE1WdC1pWVU


Output:

1 Whole Number ChoiceResult 16 P 2.09228E+13 4 fs

1 Whole Number ChoiceResult 15 S 120 4 6 0

Add a comment
Know the answer?
Add Answer to:
Must be written in VBA Create a program called moremath to request a whole number, n,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++, Create an int variable called first and fill it with a whole number taken...

    In C++, Create an int variable called first and fill it with a whole number taken from the keyboard. Create another int variable called second. Output the sum of first and second, product of first and second, difference of first and second, and the modulus of first and second.

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory...

    Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory of a store. The program must have a menu that allow to perform the following three actions: Add a new item Remove an item Replicate n times and existing item The program must have two dynamic arrays: one for store the name of the product and other to store the price of the product. The size of each array must be of the same...

  • Exercise 7.1 (lettercount.py, design). Before attempting to program lettercount.py, create a file called design that includes...

    Exercise 7.1 (lettercount.py, design). Before attempting to program lettercount.py, create a file called design that includes some analysis on how you think the problem will be solved. Examples include: a flowchart of events in the program, pseudocode, or a step by step process written in plain english. If you choose to scan your design please make sure that it is legible. Next write a program that reads in a string on the command line and returns a table of the...

  • Program must be written in C++: Create a parent class called CompSciProfessor. Each professor has name...

    Program must be written in C++: Create a parent class called CompSciProfessor. Each professor has name (type string), email (type string), and facultyId (type long). Specialize the CompSciProfessor class into two more classes: AdjunctProf, and TenureTrackProf classes. The specialized class AdjunctProf has three attributes of its own: degree (type char), NoOfTA (type int), and NoOfCourses (type int). The attribute ‘degree’ refers to the degree of the adjunct professor. You assign ‘B’ to represent bachelor degree, ‘M’ for Master degree, and...

  • 5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create...

    5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create a method called generateSuperLottoNumbers() that returns an array of 6 random SuperLotto lottery numbers. The first 5 numbers must be from the range 1 to 47 The 6th number (the MEGA) must be from 1 to 27. Create a method called printTicket() that takes an integer array as an parameter it will loop through the integer array and print out the data Display the...

  • I need this problem to be solved in Excel VBA code. Need full code in VBA....

    I need this problem to be solved in Excel VBA code. Need full code in VBA. Please solve 1st Task : '5 or 0'. Please help me urgently with proper answer and coding solutions which I can run in Excel/vba. Thanks Course: Programming languages Second laboratory work File and string processing Create a program that processes text file according to task variant. Requirements: 1. Create text file (use notepad) with some lines of data according to task variant. 2. Ask...

  • Important: This code must be written without the use of <and> or range. Create the Congress...

    Important: This code must be written without the use of <and> or range. Create the Congress Program as Python program: A) A person is eligible to be a US senator if they are at least 30 years old and have been a US citizen for at least 9 years. B) To be a US representative these numbers are 25 and 7, respectively. C) They are not eligible for either if...? Your program will accept a person's age and years of...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT