Hi! I challenged myself to do another task but I was stuck again... I was tasked to find the product of positive integers using functions. The code will stop receiving answers when the user inputs either a zero or a negative integer. The code will then find the product of the entered numbers and will display the product. I got almost everything but the output wasn't as it should be.
We were given specific functions we can use. We can also add or modify them.
int accept_number()
bool ispositive(int)
int product(int, int)
void display(int)
#include <iostream>
usingnamespace std;
int accept_number();
bool ispositive(int);
int product(int, int);
void display(int);
int main() {
int prod {};
for (int enter {}, prev {1}; ispositive(enter = accept_number()); prod = product(enter, prev), prev = prod);
display(prod);
}
int accept_number() {
int x {};
cout << "Enter a number: ";
cin >> x;
return x;
}
bool ispositive(int a) {
return a > 0;
}
int product(int m, int n) {
return m * n;
}
void display(int ans) {
cout << "\nThe product is: " << ans << '\n';
}