Loops OR Functions!! HELP WITH THIS CODE!!!!!!!!!!

This is a discussion on Loops OR Functions!! HELP WITH THIS CODE!!!!!!!!!! within the C++ Programming forums, part of the General Programming Boards category; this is the code #include <iostream.h> int mult(int x, int y); int main() { int x, y; cout<<"Please input two ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    Loops OR Functions!! HELP WITH THIS CODE!!!!!!!!!!

    this is the 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;
    }

    the codes fine i just want it to say pick another number then repeats the code again! Can any1 help me ?
    Thankz
    ICE

  2. #2
    Unregistered
    Guest

    Smile

    loops...

    read more about loops, then you'll have a good idea of how to use for, while, or do/while loops.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    49
    Hmm..
    Do something like this:
    #include <iostream.h>
    int mult(int x, int y);
    int main()
    {
    int x, y;
    char again;
    cout << "Would you like to run the program?(y/n) " << endl;
    cin >> again;
    while (again == 'y') {
    cout<<"Please input two numbers to be multiplied: ";
    cin>>x>>y;
    cout<<"The product of your two numbers is "<<mult(x, y) << endl;
    cout << "Would you like to run the program again? (y/n) ";
    cin >> again;

    }
    cout << "Thank you for trying my program. " << endl;
    return 0;
    }

    int mult(int x, int y)
    {
    return x*y;
    }
    Sorry about not adding comments, but most of the code is pretty self explanitory.
    Good luck,
    Kavity
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    What about this?

    #include <iostream.h>
    #include <ctype.h>

    int mult(int x, int y);

    int main()
    {
    int x, y;
    int sentinel = -1;
    char choice;
    do{

    cout<<"Please input two numbers to be multiplied: ";
    cin>>x>>y;
    cout<<"The product of your two numbers is "<<mult(x, y);
    cout << "\n\nEnter values again <Y:N>: ";
    cin >> choice;
    choice = toupper(choice);
    if(choice != 'Y')
    sentinel = 0;
    cout << "\n";

    }while( sentinel == -1);

    return 0;
    }
    int mult(int x, int y)
    {

    return x*y;
    }

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    Bah.

    Let him do what he wants. I was just stating an easy way to do it
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  2. How to code these functions?
    By Cicci in forum C Programming
    Replies: 15
    Last Post: 07-10-2007, 02:52 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 10-03-2002, 04:04 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21