Making a loop with input

I am using microsoft visual studio 2013 console application and what I am trying to do with my code is say "Hello" and if the user types "Goodbye" then the program closes ...however if they type anything else then the program repeats "Hello" ...I am not having very much luck getting it to loop around so I decided to ask here although I do know i could just copy and paste my code in the else statement so it asks however many times I paste it into itself but that'd be a waste of space and not really what I want.

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
  // ConsoleApplication2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

string statement1;
string answer = "Goodbye";
string sentance1 = "Hello";

int update()
{
	if (statement1 == answer)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main()
{
	cout << sentance1;

	getline(cin, statement1);

	return update();
}
1
2
3
4
5
6
    std::string in;
    while (in != "Goodbye")
    {
        std::cout << "Hello";
        std::cin >> in;
    }


For update just write:

return statement1 == answer;

There is no need to branch.
oh I was just making it complicated ...thanks very much ...I know its off topic but do you know why when I have just cout<< "Hello"; my window will close instantly? i have tried things like system("pause") and all the funny ways posted in other forums but none of them seem to work for me
do you know why when I have just cout<< "Hello"; my window will close instantly?

http://www.cplusplus.com/forum/beginner/1988/

BTW, you really don't want to return the result of update() as the result of main. Returning a non-zero value generally tells the operating system your program didn't run successfully. You should always return 0; unless you have a reason to do otherwise.
Topic archived. No new replies allowed.