Assignment 6 For this assignment, you'll prompt the user for a number. While we've done this before, this time, we're going to make the input a little more sophisticated by moving it to a new method that will capture the number as well as make sure the number is within the correct range. By separating logic like this into methods, you can see how easy it can be to reuse this logic any time you need to get input by just calling a simple method. Create a method GetNumber that is: • public • static • returns an int • accepts 2 parameters, an int for lower limit and an int for upper limit Logic within the method should do the following: 1. Prompt the user to enter a number between the lower and upper limit specified; see the format below expected below. 2. Check if the number entered is valid, falling within the lower and upper ranges specified. If the number is not valid, continue to prompt the user until a valid number is entered 3. Return the validated number from the method. From the main method, call the GetNumber method using inputs of 0 and 10. Then, print the statement You entered X, where X is the number returned from the method. Sample Output The following example assumes the method is called with a lower limit of 0 and upper limit of 10: Enter a number between 0 and 10: 42 Enter a number between 0 and 10: -5 Enter a number between 0 and 10: 8 You entered 8
Assignment 6 For this assignment, you'll prompt the user for a number. While we've done this before, this time, we're going to make the input a little more sophisticated by moving it to a new method that will capture the number as well as make sure the number is within the correct range. By separating logic like this into methods, you can see how easy it can be to reuse this logic any time you need to get input by just calling a simple method. Create a method GetNumber that is: • public • static • returns an int • accepts 2 parameters, an int for lower limit and an int for upper limit Logic within the method should do the following: 1. Prompt the user to enter a number between the lower and upper limit specified; see the format below expected below. 2. Check if the number entered is valid, falling within the lower and upper ranges specified. If the number is not valid, continue to prompt the user until a valid number is entered 3. Return the validated number from the method. From the main method, call the GetNumber method using inputs of 0 and 10. Then, print the statement You entered X, where X is the number returned from the method. Sample Output The following example assumes the method is called with a lower limit of 0 and upper limit of 10: Enter a number between 0 and 10: 42 Enter a number between 0 and 10: -5 Enter a number between 0 and 10: 8 You entered 8
Chapter7: Using Methods
Section: Chapter Questions
Problem 1CP
Related questions
Question
100%
Hello, I need help with this assignment, please. I need to prompt the user for a number using multiple methods in a single class. This has to be done through #C language and I am doing it through Visual Studio, have tried to solve this but I failed to get the right outputs, its really confusing to me, thank you for your help.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,