need help with some code

so i want this exit statement to go back to whatever the user was doing before but when you say yes it just exits out and doesn't redo the script. suggestions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool exit()
{
	char exit;
	do{
		cout << "again? (y/n):\n";
		cin >> exit;
		if ( (exit == 'Y') || (exit == 'y') )
    return true;
		
 } while ( (exit != 'N') && (exit != 'n') );

 return false;

 }

How are you calling this function?

And the way it's currently set up, if they say yes, you're telling the program to exit. I think you mean to return false on line 8 and return true on line 12.
i am calling the function at the end of main() like so:

1
2
3
4
5
6
7
8
9
10
11
if (ans == 1)
		Print_out(n);
	if (ans == 2)
		Array(b);
	if (ans == 0)
		exit(0);
	exit();
	
	char ch;
	cin >> ch;
	return 0;
Well you're currently only telling it to call the function once. You're calling exit(), and then not doing anything with its return value.

You'll probably want to put it into a loop like this:
1
2
3
do {
    // your actually program goes here
} while(exit());
sweet! thank you. the true/false was in the right place i just had to put that do loop in the main().
Yes, I was confused as to how you were calling it in my first post, you had it right before.

Glad to help, anyhow.
Topic archived. No new replies allowed.