-
functions
I am having difficulty understanding functions and how to write a program using one. Foe example, I need to write a program that takes a number from the user and prints a diamond.
I need to use functions to tell the program hoe many spaces to print and how many * to print. Can any one hellp me please?
Thanks
-
for functions read some tuts. It will click soon. They are not hard to understand especially when you see them working. As for the other its been done about a zillion times now in all sorts of fancy ways ( well by prelude anyway ). Im certain a board search will be all you need to do your homework.
-
Hi,
Here is an example program which calls a function:
Code:
#include <iostream>
using namespace std;
void DoubleThenPrint(int a)
{
cout<<2 * a<<endl;
}
int main()
{
int a = 4;
DoubleThenPrint(a);
return 0;
}
-
how do I call the function to print both spaces and stars using the exact same function?
-
A function is just like a miniature program--you're not limited to one line of code. You can make the function do anything you want. It can be 10,000 lines long, and print every character possible in a representation of the Mona Lisa. If you want the function to print a space, then do this:
cout<<" ";
If you want your function to print an asterisk next to the space, then do this:
cout<<"*";
Like magic, your function will have printed a space and an asterisk