This topic is now archived and is closed to further replies.


Help appreciated - printing loop

Recommended Posts

Hello, I would like to know 2 things that I cant find in my C++ books: 1. Could someone please show me how I can use a function to print another functions output x amount of times, where x is input by the user. Ex. int line( int b ) { return square( b )??????? } int square( int a) { if ( a == 0 ) return 0; cout << "*"; return square( a - 1); } It seems to be as easy as just telling line() to return square( b) but that didnt work and everything else I have tried does NOT work, and this has been driving me nuts. ANY HELP APPRECIATED 2. How do I make a function return an asterik *, or a word. Ex. return *; OR do I put return " * "; AS for a word do I put return cout << "hello"; or just... return "hello"; none seem to work for me... ANY HELP WITH THE ABOVE 2 PROBLEMS WOULD JUST BE SUPER!!!! AND WOULD HELP A LOT. ANY HELP APPRECIATED!!!! Sincerely Me. Edited by - felisandria on August 9, 2001 10:07:56 AM

Share this post

Link to post
Share on other sites
returning integers and other numbers/Structures is relatively easy

struct MYDATA{
char word[20];
int myNumber;

int myFuction(int Number)
int myRetunNumber;

myRetunNumber= square(number -1);

return myRetunNumber;

char myOtherFunction(char character)
if(character == ''a'')
return ''A''
if(character == ''c'')
return ''C''
return character;

MYDATA mySuperFunction()
MYDATA SomeStuff;

SomeStuff.word = "hello";
SomeStuff.myNumber =1;

return SomeStuff

void main ()
int aReturnedNumber;
MYDATA someSameStuff;

for(int i = 0; i<5; i++){
aReturnedNumber = myfunction(45+i);
printf("%i",&aRetunedNumber); //not to sure how to do that
//with cout
if(myOtherFunction(''a'') == ''A'')
someSameStuff = mySuperFunction();
printf("%c %i",&someSameStuff.word, &someSameStuff.myNumber);

as for string well thay are a cow... they are a bit of a bugger, usually its best to return apointer to a string of chars and i carnt think of how otherwise to do it of the top of me head x cept for including the variable for the string within a structure

~prevail by daring to fail~

Share this post

Link to post
Share on other sites