GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Dec-2005, 02:46
J-a-Y J-a-Y is offline
New Member
 
Join Date: Dec 2005
Posts: 6
J-a-Y is on a distinguished road

times table program


i need help making a program that makes the times tables appear after you enter a number. for e.g if you enter 2 it comes up with
1*2=2
2*2=4
etc
all way down to
12*2=24

i need this to happen from when you type in any number from 1 - 12 and it needs to give the times table like above for any numbers. any help will be appriciated jay
  #2  
Old 13-Dec-2005, 06:49
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

Re: times table program


Sounds Like Homework
  #3  
Old 13-Dec-2005, 06:53
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: times table program


Hello Jay,
Welcome to GIDForums.

To print the tables, you need a loop.

Consider that the number is x.
Then, the first line should print:
1 * x = answer
2 * x = answer
and so on.
For example, consider that the number is 2 as you said.
Then, :
1 * 2 = 2;
2 * 2 = 4;

What can we do about this?
We can have a variable i, that varies from 1 to 12.
If x is the input, then the psuedo code looks like:
Quote:
For i varies from 1 to 12
print "i * x =" i*x

But how to code this in program?
Use the for loop, which you can use for this program.
First get the input from the user.(I hope you know how to do this )
Then, in a loop, like this:
CPP / C++ / C Code:
for( i = 1; i <= 12; i++ )
What does this loop do? It varies i from 1 to 12.
At the first iteration, i is 1.
After the end of the iteration, the value of i is incremented by 1.
This is indicated by the "i++" statement.
And the loop goes on.. When the value of i becomes greater than 12, the loop exits.

So, you have to print the Values inside the loop.
In C, you can use the printf statement.
For example, like this:
CPP / C++ / C Code:
printf( "%d * %d = %d \n", i, x, i*x );
%d indicates an integer, and '\n' indicates a line break.
So, the first %d corresponds to i, second %d corresponds to x, and the third %d corresponds to i*x.

Now, Are you ready for another challenge?
Print All the tables from 1 to 10.
(Hint: Use Another loop.)

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #4  
Old 14-Dec-2005, 04:50
J-a-Y J-a-Y is offline
New Member
 
Join Date: Dec 2005
Posts: 6
J-a-Y is on a distinguished road

Re: times table program


Ok cheers anyway i do get what you all said, and yes it was home work but we have only got the basics of C++ and he expects us to do that. and for a newbie u gotta admit its kinda hard!
  #5  
Old 14-Dec-2005, 14:18
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Re: times table program


Welcome to GID

Quote:
Originally Posted by J-a-Y
and for a newbie u gotta admit its kinda hard!

For a newbie who is afraid of the library
But I see Paramesh did an excelent job (as always - Keep them coming, Paramesh) in giving you more then just code.

Kobi.
__________________
It's actually a one time thing (it just happens alot).
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a file in [c] i hate c C Programming Language 15 21-Nov-2005 12:52
Type casts ? kai85 C++ Forum 12 23-Jun-2005 12:04
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30
Help with simple math table program (was a SIMPLE program) Bubba C Programming Language 3 09-Mar-2005 12:40
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:45.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.