Friday, February 1, 2008

Functions!!

These past two days I've been working with functions. Actually, I haven't done all that much. Yesterday (Thursday) was not a very productive day. The extent of my learning was reading about functions on the C++ Tutorial site. Due to many distractions, I never got to the coding part. Today, however, I did. It was as easy as I figured it to be. My only problems were human error (forgetting an int main() and a few ;'s. I actually solved a problem on my own, but it turned out to be my own fault again. I forgot to add cin.get(); at the end. Here is the code:


#include

using namespace std;

int mult ( int x, int y );
int main()
{
int x;
int y;

cout<<"Please input two numbers to be multiplied: ";
cin>> x >> y;
cin.ignore();
cout<<"The product of your two numbers is "<< mult ( x , y ) <<".\n";
cin.get();
}

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

This program, which is an example from the tutorial, asks you for two numbers and multiplies them. A very basic example of functions.

I still have more to work on with the functions. The more advanced functions will be tougher and, judging by what's ahead of me in the tutorials, I might want to spend more time with the simpler things and make sure I have them down.

1 comment:

GeekTeach said...

Any comments on Zhanar's presentation? Feel free to post them on her Blog.

http://zorbax.blogspot.com


~Richard.