Test: Computer Science

USING FUNCTIONS

1.

Consider the following C++ code to perform the following subtraction:

9 - 6:

 

#include <iostream>

using namespace std;

int main() {

int total = 0;

cout << "This code performs the following math operation: 9 - 6 = ";

total = sub(6,9);

cout << total;

}

 

int sub(int num1, int num2) {

return (num2 - num1);

}

 

Is there anything wrong with the code?

The arguments in total should be flipped. Such as: total = sum(9,6);

The code is missing the math library. It should have

#include

There is nothing wrong with this code.

The function prototype is missing.

1/1 questions

0%

Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors