Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help appreciated - printing loop


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Blood_Dragon   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 August 2001 - 07:20 AM

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

Sponsor:

#2 Zerosignull   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 August 2001 - 07:51 AM

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''
else
character++;
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'')
exit(0);
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~




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS