#include <iostream>

using namespace std;

int main()
{
    char exit;
    
    cout << "Exit? Y / N " << endl;
    cin >> exit;
    
    if ( exit == 'Y' || exit == 'y' )
       { }
       
    if ( exit == 'N' || exit == 'n' )
        system("PAUSE>nul");
        
    else
    { }
    
}

I solved through trial and error, heres the code if you ever want to use it, thanks :)

I guess you could change

else
    { }

To

else
    cout << "Invalid Selection!" << endl;

Hope this helps.

Actually i'm trying to improve this now, i've figured i'll need a loop?

Because i want to change it so that if the user inputs a different char/int than Y/N it will cls and re-ask question,

Heres what i've got

/* Simple users decision to exit program */

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char exit;
    
    cout << "Exit? Y / N " << endl;
    cin >> exit;
    
    if ( exit == 'Y' || exit == 'y' )
       { }
       
    if ( exit == 'N' || exit == 'n' )
        getch();
        
    else
        system("cls");
        cout << "Exit? Y / N " << endl;
        cin >> exit;

}

If the user enters another char/int it cls's and asks again but if they enter a char/int again it closes, please help :)

what the meaning of this function, and how and when to use it?? it doesn't requires aspecific header file

system("PAUSE>nul")

system("PAUSE>nul")

system tells C to call a windows command in this case he's calling pause. you can go to a dos prompt and type pause to see the effect.

This is a old post but i thought I would post my suggestion to the problem.

With the code below: The problem that I see is if you type N or n it runs the program, but typing anything else (not just Y) causes it to exit.
So maybe change the wording to say type N to run or any key to exit.

// put a # infront of include I can't figure out how to get it to display here

include <iostream>

using namespace std;
int main()
{
char exit;
cout << "Exit? Y / N " << endl;
cin >> exit;
if ( exit == 'N' || exit == 'n' )
{cout << "Ok, running program";}
else
{cout << "Ok, now exiting" << endl;}
return 0;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.