bool testSmoking(char s, char smokingPref)
{
if (s == smokingPref)
return true;
else
return false;
}
i know i have to add it to the while loop but i dont know how to add another function right next the one there... do i have to make a seperate loop? please help!
In main, assign variables in a different set of lines, after that, encapsulate all of main (including assignments) but your variable declarations in a do-while loop (if for no other reason than it's good form to have a pretest loop for something like this). Once that's done, you tag on a little bit on the end (inside the loop) asking if the user is finished, if so, complete the loop requirement, and viola; if not, clear everything out, and start again.
I'm a little green with C++, but that's how I'd do it in other languages, and I think the principle stays the same.
int main()
{
int variable;
char answer;
bool done = false; //declare this outside, because if it is true, the program will end anyway
do
{
variable = 0; //each time the loop starts anew, this clears out your variables
/* your code here */
cout << "Done(y/n)?";
cin >> answer;
if(answer == 'y')
done = true;
}
while(done != true); //keeps the loop up until the user returns a 'y'
return 0;
}
I'm pretty sure that's how it would work... Personally, I'd put some sort of validation on it, to keep the user from feeding something invalid into it. On that note, your code seems to lack validation for all of it's inputs, or I'm missing something... Just a concern.
You do need to declare the Boolean, as all names (identifiers) must be declared before they are used, you could get away without initialising it but it is safer to initialise variables to a safe value when (or soon after) they are declared.
bool done; //Declaration (also definition)
bool done = false; // Declaration and initialisation