J.R.
J.R.

Reputation: 1

Calling a function multiple times but it prints only once

I'm running the following code:

#include <iostream>

using namespace std;

string response(bool isMale, bool isTall)
{
    if (isMale && isTall) {
        cout << "MALE AND TALL" << endl;
    }
    else if (isMale || isTall) {
        cout << "MALE OR NOT TALL" << endl;
    }
    else {
        cout << "ELSE" << endl;
    }
}

int main()
{

    response(true, true);
    response(false, true);
    response(false, false);

    return 0;
}

the output is the following:

MALE AND TALL

Process returned -1073740940 (0xC0000374)   execution time : 1.460 s
Press any key to continue.

Why isn't the output?:

MALE AND TALL

MALE OR NOT TALL

ELSE

A different forum post hinted at a global value not being reset. I don't really know what to make of that.

I would appreciate any help

Upvotes: 0

Views: 189

Answers (1)

Tevfik Kadan
Tevfik Kadan

Reputation: 71

void response(bool isMale, bool isTall){
    if (isMale && isTall) {
        cout << "MALE AND TALL" << endl;
    }
    else if (isMale || isTall ){
        cout << "MALE OR NOT TALL" << endl;
    }
    else {
        cout << "ELSE" << endl;
    }
}

You need to change function return type "string" to "void".

Upvotes: 6

Related Questions