"Fortune Teller.exe has encountered a problem"

Ok, so after executing a loop in my program 2 times i get this error message: "Fortune Teller.exe has encountered a problem and needs to close. We are sorry for the inconvenience" Here is the coding for my fortune teller i am making. It is in the very basics so far.
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
// Fortune Teller
#include <iostream>
#include <string>

using namespace std;


string askquestion (string question)
{
    string answer;
    cout << question;
    cin >> answer;
    if (answer == "Yes" || answer == "yes")
    {

    }
    else
    {
        while (answer == "Yes" || answer == "yes" || answer == "No" || answer == "no");
        {
        cout << "Sorry, your answer did not seem to qualify. You must answer Yes or No. Please \ntry again" << endl;
        cout << question;
        cin >> answer;
        }
    }
}
int main ()
{
    string q1 = "Do you like chicken nuggets? ";
    askquestion(q1);
   return 0;
}



Activating the loop twice, putting spaces in between letters for an answer, and activating the loop once and putting in a valid answer cause this.
Last edited on
while (answer == "Yes" || answer == "yes" || answer == "No" || answer == "no");

Remove that semicolon and you should be fine. What was happening was that every time that loop was started, it can not be ended due to the semicolon making it an empty loop.

Also, you specify that the function will return a std::string, however you don't return anything at all.
Topic archived. No new replies allowed.