# Thread: Loops OR Functions!! HELP WITH THIS CODE!!!!!!!!!!

1. ## 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. loops...

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

3. 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;
}
Good luck,
Kavity

#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. ## Bah.

Let him do what he wants. I was just stating an easy way to do it