Use of functions
Nov 20, 2011 at 2:03am UTC
I really haven't found a use of multiple function yet, so can you please post a very simple program that has two functions that has to use two functions no matter what.
Nov 20, 2011 at 2:23am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
void divide(double , double );
int main()
{
double num1, num2;
cout << "Enter two numbers and I will divide the first\n" ;
cout << "number by the second: " ;
cin >> num1 >> num2;
divide(num1, num2);
return 0;
}
void divide(double arg1, double arg2)
{
if (arg2 == 0.0)
{
cout << "Sorry, I give an undefined solution.\n" ;
return ;
}
cout << "The quotient is " << (arg1 / arg2) << endl;
}
Very basic program that my instructor had us write in my class. Only two functions are here: "void divide(double, double)" and "int main()".
Nov 20, 2011 at 2:28am UTC
thx for the help
Nov 20, 2011 at 2:54am UTC
another reason to use them is that they can help keep your program more organized and let'you change a specific part of the program easier.
Topic archived. No new replies allowed.