How to convert for, statements into while loops?

  • From: Jes <theeternalkid@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 18 Jul 2010 21:38:43 -0400

Hi all,
I got my program to work correctly, but now I want to learn how to convert the 
pre test loop, the for statement, into a while loop.
***code**
//Ch8lab2.cpp
//Displays one or more multiplication tables
//Created/revised by Jes Smith on July 18, 2010

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
        //declare variables
        char anotherTable = ' ';
        int multiplicand        = 0;
        int product                     = 0;

        do
        {
                //get the multiplicand
                cout << "Enter the multiplicand: ";
                cin >> multiplicand;

                //display the multiplication table
                for (int multiplier = -1; multiplier < 10; multiplier += 1)
                {
                        product = multiplicand * multiplier;
                        cout << multiplicand << " * " << multiplier
                                << " = " << product << endl;
                }       //end for

                cout << endl;
                cout << "Display another multiplication table? (Y/N) ";
                cin >> anotherTable;
        } while (toupper(anotherTable) == 'Y');
        return 0;

} //end of function

Other related posts: