»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 02-11-2004, 09:11 PM   #1 (permalink)
Registered User
 
Join Date: Jun 2003
Location: Maine
Posts: 24
Elburn is on a distinguished road
C++ question on void functions.

I'm not sure if this is the right place but..

I have a void function thus:

void rowout (int columns)
{
int x(1);
while (x <= columns)
{
cout<<"*";
x += 1;
}

cout<<endl;
return;
}

This should print out a row of *s dependent on how many columns the user wants.

Now, back in the main function, I have another while loop that will tell how many times to makes these columns (it is the row loop and will make that line for how ever many rows)

Now, I'm trying to call this void function within the int main () while loop. I've tried putting cout<<rowout; but it gives me some hex stuff, and I can't figure out how to correctly invoke it.

Any help would be appreciated.

Elburn is offline   Reply With Quote
Old 02-11-2004, 09:16 PM   #2 (permalink)
Registered User
 
eagle1's Avatar
 
Join Date: Oct 2001
Location: La Isla del Encanto
Posts: 4,125
eagle1 is on a distinguished road
If I remember correctly, you need to call from main but you need this:

cout<<rowout(columns -- or whatever variable you are using);

So... you need to put the parenthesis of the function and the number that you are going to send to the void function.
__________________
boo!
eagle1 is offline   Reply With Quote
Old 02-11-2004, 09:47 PM   #3 (permalink)
Registered User
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: So. Californication
Posts: 1,659
lost-and-found is on a distinguished road
Send a message via AIM to lost-and-found
so do you have something like:
Code:
int /*(or void)*/ main(){
   int x=0,rows,columns;
   cout<<"How many rows do you want?";
   cin>>rows;
   cout<<"How many columns do you want?";
   cin>>columns;
   while(x<rows){
          rowout(columns);
          x++;
   }
   return 0; //if you so please
}
edit: forgot a ";" and I guess you don't need the "cout<<endl;" in the main if you have it in the rowout() already

edit 2- I forgot to add an "x++ in the loop" (stupid me)
__________________
To fry or not to fry...oh what the heck, let it fry :)

Last edited by lost-and-found; 02-11-2004 at 09:55 PM.
lost-and-found is offline   Reply With Quote
Old 02-11-2004, 09:56 PM   #4 (permalink)
Registered User
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: So. Californication
Posts: 1,659
lost-and-found is on a distinguished road
Send a message via AIM to lost-and-found
got this output when I mixed my main() with your rowout() is that what you wanted?
Quote:
How many rows do you want?5
How many columns do you want?4
****
****
****
****
****
Press any key to continue
edit- also, your function is void, you don't need a "return;" in the rowout() function, since you aren't returning anything.
__________________
To fry or not to fry...oh what the heck, let it fry :)

Last edited by lost-and-found; 02-11-2004 at 09:58 PM.
lost-and-found is offline   Reply With Quote
Old 02-11-2004, 10:01 PM   #5 (permalink)
Registered User
 
eagle1's Avatar
 
Join Date: Oct 2001
Location: La Isla del Encanto
Posts: 4,125
eagle1 is on a distinguished road
Exactly what I meant!
Nice example for the main.
__________________
boo!
eagle1 is offline   Reply With Quote
Old 02-12-2004, 02:22 PM   #6 (permalink)
Registered User
 
Join Date: Jun 2003
Location: Maine
Posts: 24
Elburn is on a distinguished road
Thanks for the help, I got it working now.

I didn't realize that i didn't need to have the cout when calling the void function.
Elburn is offline   Reply With Quote
Old 02-12-2004, 05:35 PM   #7 (permalink)
Registered User
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: So. Californication
Posts: 1,659
lost-and-found is on a distinguished road
Send a message via AIM to lost-and-found
do you mean like: "cout<<rowout(columns);"? well when you have the cout, it is expected that rowout() returns something then. That's why it gave you hex since there was nothing being returned. when you just have "rowout(columns);" the program knows all the work is done in the function rowout() and the program is not expecting rowout() to return any value.
__________________
To fry or not to fry...oh what the heck, let it fry :)
lost-and-found is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 10:53 AM.