Q:

How to use looping in C++

I am new to C++ and I am making a program to generate a multiplication table. Here is he code.
#include <iostream>
using namespace std;
int main()

{
  int num;
    cout << "Enter a number to find Multiplication Table   ";
       cin >>num;

            for(int a=1;a<=10;a++)
                     {
                        cout<<num<<" x "<<a<<" = "<<num*a<<endl;

                     }
       cout << "Press ENTER to continue...\n";
       cin.get();
       getchar();
       return 0;

}

I want that after the multiplication table of one number is displayed , the user should have an option of entering another number or exiting.
Like press "n" to enter a new number or "e" to exit

A:

This may be what you want. (this is the implementation of main function)
int num;
char command;
bool exit=false;
while(!exit)
{
    cout << "Enter a number to find Multiplication Table   ";
    cin >>num;

    for(int a=1;a<=10;a++)
    {
         cout<<num<<" x "<<a<<" = "<<num*a<<endl;
    }

    cout << "Press n to continue or e to exit\n";
    cin >> command;
    while(command != 'n' && command != 'e')
    {
        cout << "Just press n to continue or e to exit!\n";
        cin >> command;
    }
    if (command == 'e')
    {
        exit=true;
    }else
    {
        exit=false;
    }
}
return 0;

