htdefiant
Sep 23 2007, 06:45 PM
| | I'm looking for some brainstorming help. The task is to create a program where the user enters two integers, and have them multiply without using the multiplication function. For example, if the user enters 5 and 10, the program is supposed to go 10+10+10+10+10, not 5*10. I have gotten as far getting input from the user. I am thinking of using a while loop for this. Does anyone have suggestions as to the best way to do this with the while statement? Thanks. |
Reply
galexcd
Sep 23 2007, 07:25 PM
I think a for loop would be easier: CODE int total=0; for(int i=0;i<firstnumber;i++) total+=secondnumber;
Reply
htdefiant
Sep 23 2007, 07:34 PM
I am not familiar with or loops. Perhaps you could describe the best method to use with a while loop? Thanks for your help.
Reply
galexcd
Sep 23 2007, 08:25 PM
Sure it just takes a little bit more code for the same results: CODE int total=0; int i=0; while(i<firstnumber){ total+=secondnumber; i++; }
Reply
htdefiant
Sep 23 2007, 08:38 PM
Sorry to keep perpetuating this - you've been very helpful - what is that programming in C, not C++? Thanks for you help, A fellow OS X geek
Reply
galexcd
Sep 23 2007, 08:49 PM
It actually should work in both c and c++, and even java if you declare those variables inside a method. Most programming languages have extremely similar syntax.
Reply
htdefiant
Sep 23 2007, 10:27 PM
Sorry Alex - I am very new at this. Here is what I have: CODE main ()
{ int num1, num2, num3; printf("Please an integer:\n"); num1=GetInteger(); printf("Please a second integer:\n"); num2=GetInteger(); while (num2>1) { } getchar (); return 0; } How do I apply the code you gave me to this base?
Reply
galexcd
Sep 24 2007, 02:45 AM
try this... num3 is the result of num1 times num2 CODE int num1, num2, num3=0; printf("Please an integer:\n"); num1=GetInteger(); printf("Please a second integer:\n"); num2=GetInteger(); int i=0; while(i<num1){ num3+=num2; i++; } getchar (); return 0; }
Reply
htdefiant
Sep 24 2007, 06:02 PM
galexcd
Sep 24 2007, 08:00 PM
QUOTE(htdefiant @ Sep 24 2007, 11:02 AM)  Thanks Everything works how it should? No more problems? If so great and good luck with the rest of the project. Feel free to PM me with any questions you still may have!
Reply
Similar Topics
Keywords : multiplication, addition
- Suspended Account Warning Addition
(3)
Addition To The Hide Tag
(4) We all love the hide tag ooooooo boy you cant see me untill you CLICK ON ME!! YAY!
ooooo fancy! but I think it would be even cooler if you could set some text to describe what
is going to be inside the hidebox that goes away when clicking on the show/hide link. Something
like this: That would be the "hidden" state, and when clicking on the show/hide it would hide the
preview and show the regular content. You could still have the original functionality by keeping
the same syntax, but if you want to add the preview you could have it be something ....
Wellnesspositive.com
A new addition to Xisto! (6) Hello Members, We are proud to announce Xisto's Health site, WellnessPositive.com . Here you
will find detailed information to help you on the road towards a healthier and happier life. Topics
on this site range from Physical Fitness to Weight Loss; from Body-Building to effective
Self-Defense; from Meditations that calm the mind, to ancient eastern Philosophies that will help
you walk the paths of this life with courage and contentment!! The aim of this site is
simple - it is to help people to be healthy and happy, calm and content. Here on these pages....
Please Review My New Addition And Help Required
(7) I'm currently working with my dream project at http://www.laschatz.info/ I developing each
single section and then updating the website. Now I've added the "Toolz Vault" section, this
section lists a collection of hand picked softwares that are very useful to web designers,
application developers, graphics designers and administrators. You can find the new section at,
http://vault.laschatz.info/ I've used WordPress to provide the Content management facility.
I've made a Custom theme for Wordpress that matches with the Main website and also makes th....
Buffalohelp's Personal Page
addition to my signature (0) To keep my signature down to optimized size, I decided to create this post to be the amendment to my
signature. This is posted in NO POST COUNT section. For those who would like to create something
similar, be sure to post in LIFE TALK (no post count) area. Gift Sigs received from fellow Trap17
members: 1. Saint Michael 2. Johnny 3. KuBi 4. Saint Michael 5. KuBi 6. BlaqueMajik 7.
snlildude87 8. Saint Michael 9. Avalon 10. hulunes 11. Plenoptic 12. KuBi Trap Award:
Plenoptic Userbar: SOTW#26 winner Razor's userbar ....
Looking for multiplication, addition
|
|
Searching Video's for multiplication, addition
|
advertisement
|
|