|
-
August 30th, 2017, 03:48 PM
#1
Review, divide two integers
Problem: "Write a value-returning function called isFactor. It should take 2 integer parameters and return true if the 2nd number can be divided by the 1st number evenly (in other words, if it has no remainder). So isFactor(4, 16) should return true because 16/4 = 4, but isFactor(4, 15) should return false because 15/4 = 3.75. Test it in int main()."
When I debug my code I get" error C4716: 'divide': must return a value", but I do not understand why I am getting that error.
Code:
bool divide(int x, int y)
{
int rest = x / y;
if (rest == 0)
cout << "True" << endl;
else
cout << "False" << endl;
}
// main function
int main()
{
int x;
int y;
//prompts user for input
cout << "Input first value: " << endl;
cin >> x;
cout << "Input second value: " << endl;
cin >> y;
if
(divide(x, y) == true)
cout << y << "can be divided by " << x << endl;
else
cout << y << "can not be divided by " << x << endl;
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|