Thread: Newbie badly needs c++ help with looping!!!!

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    22

    Question Newbie badly needs c++ help with looping!!!!

    Ok, i am wanting to loop the code below so that it would do the function already in the program over and over once it is already done...ive tried looking at the tutorial, but i cant understand the lesson on loops very well...

    Code:
    #include <iostream.h>
    
    int mult(int x, int y);
    
    int main()
    {
      int x, y;
      cout<<"Please input two numbers to be multiplied: ";
      cin>>x>>y;
      cout<<"The product of your two numbers is "<<mult(x, y);
      return 0;
    }
    int mult(int x, int y)
    {
      return x*y;
    }
    Thanks in advance for any help!!!
    Website- http://dgprog.cjb.net
    Complier- Dev C++ 4.0
    Email- [email protected]
    Completed: Comp-Master
    Working: The Excalibur (partnership with klinerr1.)

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    do you mean you want:
    Code:
    cout<<"Please input two numbers to be multiplied: ";
      cin>>x>>y;
      cout<<"The product of your two numbers is "<<mult(x, y);
    repeated say, 10 times? if so, here you go:

    Code:
    #include <iostream.h>
    
    int mult(int x, int y);
    
    int main()
    {
      int x, y;
      int i;
    
      for (i=0;i<10;i++)
      {
      cout<<"Please input two numbers to be multiplied: ";
      cin>>x>>y;
      cout<<"The product of your two numbers is "<<mult(x, y) << endl;
      }
      
      return 0;
    }
    
    int mult(int x, int y)
    {
      return x*y;
    }
    that will simply run the same operation of requesting two numbers, multiplying and printing, 10 times

    hope that clears it up
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I'm feeling generous today

    for loop:

    for(/*this is the initial value*/; /*this is the circumstance that terminates the loop*/; /*this is where you increment stuff*/)

    for example:
    Code:
    for(int i = 0; i < 256; i++) {
    
    }
    means int i starts at zero and keep adding one to i until it hits 256.

    while loop:

    while(/*this is the circumstance that terminates the loop*/)

    example:
    Code:
    int i = 0;
    while(i < 256) {
        i++;
    }
    meaning while i is less than 256 increment it.

  4. #4
    Akilla
    Guest

    Smile For loop

    now that you've learnt for loop...
    here's a forever loop :-)
    also called infinite loop... but i call it forever loop for giggles... :-)
    PHP Code:
    do
    {
          
    cout << "Orey, elaagunnavu ?" ;
          
    cin >> javaabu;
    }  while (
    1==1); 
    while 1=1, this thing keeps repeating ..

    COOL PROGRAMS @ www.akilla.tk

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    106
    u can do it by tthe code below

    if(m=0;m<100;m++){ doo something }

    this means m is started from 0 and after every loop m is added 1 so this loop goes for 100 times not 99
    C++ Makes you Feel Better

    "Gravity connot be held reponsible for people falling in love"--Albert Einstein

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    hehe Heres a fun way to make an application break

    for(m = 0; m < 100; m++) {
    int x = (1 << m);
    }

    This is the sort of thing that compilers don't usually catch, and windows doesn't know how to handle.

    Thus completes your lesson on how to make and break loops for today

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    it works fine.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looping switch structure Help (newbie)
    By Monte2 in forum C Programming
    Replies: 2
    Last Post: 12-02-2005, 03:16 AM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie ... looping problem
    By StupidIntel in forum C++ Programming
    Replies: 12
    Last Post: 05-13-2004, 06:45 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. Newbie needs C++ help with pauses- help needed badly.
    By dgprog in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2002, 05:11 PM