I am working on a code and I want it to ask if I want it to enter another number... when I hit "y OR Y" it repeats but the code. I don't know how to make it output "bye" when I type "N or n". Can someone please help me? Thanks.

this is part of the code that I have for Y/y which is working but I need to output something for N/n.

bool Continue()
{
    char decision;
    cout<<"\nDo you want to enter another number?(Y/N):";
    cin >> decision;
    return (decision=='y')||(decision=='Y');
}
if(!Continue())
{
   cout << "bye" <<endl;
}

is this what you want?

if (!Continue())

is the same as saying

if (Continue() != true)

is the same as saying

if (not Y/y)

How do you get a program to work without using a global variable? I looked up a global variable and I just thought it meant when the variable is outside of int ().

A global variable is a variable that you can access from every scope. That is, you would normally define it outside any function, and all of your functions would have access to it

Local variables are defined it inside your function, and are passed as an argument to any other functions that might need access to them.

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.