Examine the following code block.The code has either a syntax or logic error in one line only.Identify the problem line then write it out correctly in the box provided.Your answer must be exact, including correct spelling and spacing.void getRandNum(int low, int high) { // return a value from within the range given int myNum = 0; myNum = rand() % high + low; return myNum;}
Question
Examine the following code block.The code has either a syntax or logic error in one line only.Identify the problem line then write it out correctly in the box provided.Your answer must be exact, including correct spelling and spacing.void getRandNum(int low, int high) { // return a value from within the range given int myNum = 0; myNum = rand() % high + low; return myNum;}
Solution
The problem is with the function declaration. In C++, a function must have a return type. In this case, the function is supposed to return an integer, but it is declared as void. The correct function declaration should be:
int getRandNum(int low, int high) { // return a value from within the range given
int myNum = 0;
myNum = rand() % high + low;
return myNum;
}
Similar Questions
On Python line 5, use random.randint() to generate a number between 0 and 2, and store the result to a variable named randomNumber.
lect the correct answerWhich of these method return a pseudorandom number?Optionsrand()randomNumber()random()randGenerator()
In the function, reassign computerNumber to a random number between 1 and 3 (use randomInt() )
Which of the following is correct to obtain a random integer between 5 and 10 (inclusive)?You Answered 5 + Math.random() * 6 5 + (int)(Math.random() * 5) 5 + Math.random() * 5 Correct answer 5 + (int)(Math.random() * 6) Question 14Tips1 / 1 ptsWhat is the output of the programme below?public static void main(String[] args) { int x = 0; while (x < 10) { if (x & 2 == 0) { System.out.print(x + “ “); } x++; }} 0 1 2 3 4 Correct! 0 2 4 6 8 2 4 6 8 10 1 3 5 7 9 Question 15Tips1 / 1 ptsConsider the program below: public static void main(String[] args) { int numThings = 0; for (int i = 0; i <= 10; i+=3) { numThings++; } }How many times does the body of the for loop run? 9 10 0 Correct! 4 Quiz score: 11 out of 15Submission details:
public class TestNumbers{ public static void main(String[] args) { // Get a random number from -10 up to 10. int number = (int) (Math.random() * 21) - 10; System.out.println("The number is " + number); // is it positive? if (number > 0) { System.out.println(number + " is positive!"); } // is it 0? if (number == 0) { System.out.println(number + " is zero!"); } // is it negative? // Add another if statement }}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.