How to make the number change permanent

How do I make it so the new value assigned to times is permanent? They all output 0.

#include <iostream>

using namespace std;

int times = 0;
void restaurant();

int main ()
{
cout << times << endl;
cout << times << endl;
cout << times << endl;
}

void restaurant()
{
cout << "You've been at the restaurant " << times << " times" << endl;
times++;
}
Try calling restaurant() in main().
lastchance is correct - you never actually call your restaurant() function anywhere. You should have been able to tell this yourself, because when you run the program, you never see
You've been at the restaurant 
output anywhere.

Also:

1) You really should avoid using global variables. They seem convenient now, when you're writing tiny programs like this one. But as you write larger and larger programs, they become problematic. The sooner you can get out of bad habits, the better!

Instead of using global variables, you should learn how to pass data into, and back out of, functions.

2) What's the point of printing the same value 3 times in a row in main()? You do nothing to change the value of times between those three outputs, so how could it possibly print anything other than the same thing?
Topic archived. No new replies allowed.