Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to call my boolean function so i can use if else for the cout in c++

that my code

so in the main function I want to call the bool function but I don’t know how

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the following program:

#include <iostream>
using namespace std;
//forward declare the function
bool palindrome (string a);
int main() {
    string a;
    cout<<"Masukkan kata : ";
    cin>> a;
    
    if (palindrome(a) == true)//call the function and check the return value. 
    {
        cout<<"Kata tersebut termasuk palindrome ";
    }
    else
        cout<<"Kata tersebut tidak termasuk palindrome";
}
bool palindrome (string a) {
    int b;
    b= a.length();
    if (b == 0)
        return 1;
    else if (a[0] != a[b - 1])
        return 0;
    else
        return palindrome (a.substr(1, b - 2));
}

The output of the above program can be seen here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading