Find the error(s) in each of the following program segments and explain how the error(s) can be corrected:
(v) void theProduct() { int a; int b; int c; int result; cout << “Enter three integers “ << endl; cin >> a >> b >> c; result = a * b * c; cout << “Result is “ << result << endl; return result; }
#include <iostream>
void theProduct(){ // int instead of void or if you want to return value
using namespace std; // define namespace or std::cout, std::cin, std::endl
int a; int b; int c;
int result;
cout <<"Enter three integers"<< endl;
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is"<< result << endl;
// return result; void type returns nothing
}
Comments
Leave a comment