Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,565 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,888 people online right now. Registration is fast and FREE... Join Now!




To Program a multiplication table using while loop

 
Reply to this topicStart new topic

To Program a multiplication table using while loop

hottemp
18 May, 2008 - 03:28 AM
Post #1

New D.I.C Head
*

Joined: 18 May, 2008
Posts: 2

Hi, i'm kinda new to programming. So i got stuck trying to figure out how to program this :

To prompt user to enter an integer and then display the corresponding multiplication table for eg.

Enter an integer : 2

2 X 1 = 2
2 X 2 = 4
2 X 3 = 6
.
.
.
2 X 10 = 20

So i need someone to explain how to do it using while loop and / or for loop.

Thanx.
User is offlineProfile CardPM
+Quote Post

Wr4i7h
RE: To Program A Multiplication Table Using While Loop
18 May, 2008 - 03:59 AM
Post #2

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 14


My Contributions
Here is how to do it with a while loop; Doing it with a for loop would be very similar.

CODE
#include <iostream>

using namespace std;

int main(){
    
    int counter = 1; //initialise a counter that will start at 1
    int input;          
    
    //input
    cout << "Enter an integer: ";
    cin  >> input;
    cout << endl;
    
    //do this while your counter is less than 13 (stops at 12)
    while (counter < 13){
          //display input, a string "x" , your counter, then multiply the two and display the answer.
          cout << input << "x" << counter << "= " << input*counter << endl;
          //increment your counter, same as (counter = counter + 1)
          counter ++;
    }
    
    system("pause");
    return 0;
}

User is offlineProfile CardPM
+Quote Post

ajaymatrix
RE: To Program A Multiplication Table Using While Loop
18 May, 2008 - 05:00 AM
Post #3

D.I.C Regular
Group Icon

Joined: 15 May, 2007
Posts: 389



Thanked: 1 times
Dream Kudos: 100
My Contributions
you could use a for loop alternatively...
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:48PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month