Re: How to convert for, statements into while loops?

  • From: Tyler Littlefield <tyler@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 18 Jul 2010 19:52:25 -0600

Hello,
You could just do a while (multiplicant<10) or <11, then you can just increase 
it in the loop. a for loop is your best bet there though, if your working with 
a range.
                Thanks,
Tyler Littlefield
        http://tds-solutions.net
        Twitter: sorressean

On Jul 18, 2010, at 7:38 PM, Jes wrote:

> 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

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: