Use of return and bool
-
I need to write a program that checks the condition for all the elements of the body. If the condition is met, the yes is removed and, if not, it is false. I created two functions. One of them checks the condition, and if it is fulfilled, it returns true, and if not, it is false. But somehow I always get a yes, even if the function that checks the condition returns false. Why is that? I understand correctly that recording if (isheap) is the same as writing if (isheaprans true)? I mean, if the function isheap returned the meaning of true.
#include <fstream>
using namespace std;
bool isheap(int arr[], int n, int i);
void withdraw();int main()
{int array[] = { 1, 0, 1, 2, 0 }; isheap(array, 5, 1); withdraw(); return 0;
}
bool isheap(int arr[], int n, int i)
{
if (n * i == 100)
return true;
else
return false;
}void withdraw()
{
if (isheap) {
cout << "YES";
}
else {
cout << "NO";
}
}```
-
The simplest transfer of your code is
#include <iostream>
using namespace std;
bool isheap(int arr[], int n, int i);
void withdraw(int arr[], int n, int i);
int main()
{
int array[] = { 1, 0, 1, 2, 0 };
withdraw(array, 5, 1);
return 0;
}
bool isheap(int arr[], int n, int i)
{
if (n * i == 100) return true;
else return false;
}void withdraw(int arr[], int n, int i)
{
if (isheap(arr, n, i)) {
cout << "YES";
}
else {
cout << "NO";
}
}
I don't know what you're doing in your function.
isheap()
And why does she have a mass? ♪ ♪