#include <iostream>
#include <string>
int main ()
{
std::string input;
do
{
// enter program here
int a;
int b;
std::cout <<"Enter the first number." << std::endl;
std::cin >> a;
std::cout << "Enter the second number." << std::endl;
std::cin >> b;
std::cout << "The answer is: " << a+b << std::endl;
std::cout << "Do you want to quit?" << std::endl
<< "[Y]es [N]o" << std::endl;
std::cin >> input;
} while ((input == "N") || (input == "n"));
return 0 ;
}
I've compiled this and run it on several platforms (Kubuntu (gcc), XP (cygwin) and Solaris (gcc)) and everything seems fine to me.
If I press 'n' the program continues. If I press 'y' the program exits. I'm not sure what's going wrong for you. :(
The reason the program jumps to the start is because of the mechanics of a do-while loop. Where it says do is where the loop begins. The program enters the loop and executes the instructions until it gets to the while part.
You'll notice instructions next to while. Those are the conditions of the loop. If those conditions are true the program jumps back up to do and repeats the process until the while conditions are false.
So, when input is 'N' or 'n' the condition is true and the do-while loop repeats. Otherwise the do-while loop ends and the next instruction is executed. In this case the next instruction is return 0, which exits the program.