Why won't my program with two simple functions run?

Curious as to why this won't work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This program will return true if the user types in y, Y, yes, Yes. Otherwise, if the user types  in no, it will return false.
#include <iostream>
#include <string>
using namespace std;

// Function Prototype
void yes(string question);

int main ()
{

string answer;

// Gets the answer.
cin >> answer;

// Calls yes passing one argument.
yes(answer);
return 0;
}

bool yes(string question)
{
	bool status;
	if (question == "y" || question == "Y" || question == "yes" || question == "Yes")

		status = true;
	else 
		status = false;
}

closed account (E0p9LyTq)
You are not returning the status value in your user-defined function.

Your function prototype is returning a void, not a bool.

You are not doing any output, so you don't know if the program is working correctly or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>

bool yes(std::string question);

int main ()
{
   std::string question;

   std::cin >> question;

   bool answer = yes(question);

   std::cout << std::boolalpha << answer << "\n";
}

bool yes(std::string question)
{
   if (question == "y" || question == "Y" || question == "yes" || question == "Yes")
   {
      return true;
   }
   else
   {
      return false;
   }
}
Last edited on
Topic archived. No new replies allowed.