954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

c++ help

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');
}

justinlake888
Newbie Poster
8 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 
if(!Continue())
{
   cout << "bye" <<endl;
}


is this what you want?

Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
 

if (!Continue())

is the same as saying

if (Continue() != true)

is the same as saying

if (not Y/y)

chococrack
Junior Poster
149 posts since Oct 2008
Reputation Points: 92
Solved Threads: 16
 

thanks

justinlake888
Newbie Poster
8 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

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 ().

justinlake888
Newbie Poster
8 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

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.

stilllearning
Posting Whiz
309 posts since Oct 2007
Reputation Points: 161
Solved Threads: 43
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You