Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I got this and i don\'t know what is wrong with my code. BELOW IS THE CODE I TRI

ID: 3840179 • Letter: I

Question

I got this and i don't know what is wrong with my code.

BELOW IS THE CODE I TRIED. PLEASE FIX IT CORRECTLY.

#include <iostream>
using namespace std;


int add(int a, int b){
return a+b;
}

int subtract(int a, int b){
return a-b;
}

int main() {
int num1 = 0;
int num2 = 0;
int sum = 0; //sum of numbers
int diff = 0; //difference of numbers

cout << "Enter the first integer: ";
cin >> num1;
cout << "Enter the second integer: " << endl;
cin >> num2;
cout << endl;

cout << "First Integer: " << num1 << endl;
cout << "Second Integer: " << num2 << endl;
cout << endl;

// Call add function
sum = add(num1, num2);


// FIXME (6) Output result of num1 + num2
cout << num1 << " + " << num2 << " = " << sum << endl;


return 0;
}

Input Enter the first integer Enter the second integer First Integer 9 Your output Second Integer: 7 9 7 16 Enter the first integer Enter the second integer First Integer 9 Expected output Second Integer 7 9 16

Explanation / Answer

You didn't call the subtract function in main. You can try with the below code.

#include <iostream>
using namespace std;

int add(int a, int b){
return a+b;
}
int subtract(int a, int b){
return a-b;
}
int main() {
int num1 = 0;
int num2 = 0;
int sum = 0; //sum of numbers
int diff = 0; //difference of numbers
cout << "Enter the first integer: ";
cin >> num1;
cout << "Enter the second integer: " << endl;
cin >> num2;
cout << endl;
cout << "First Integer: " << num1 << endl;
cout << "Second Integer: " << num2 << endl;
cout << endl;
// Call add function
sum = add(num1, num2);

// FIXME (6) Output result of num1 + num2
cout << num1 << " + " << num2 << " = " << sum << endl;

// Call subtract function
diff = subtract(num1, num2);

// Output result of num1 - num2
cout << num1 << " - " << num2 << " = " << diff << endl;

return 0;
}