home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

C++ question on void functions.

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1925
Discussions: 200,936, Posts: 2,379,211, Members: 246,300
Old February 12th, 2004, 12:11 AM   Digg it!   #1 (permalink)
Member
 
Join Date: Jun 2003
Location: Maine
Posts: 170
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 February 12th, 2004, 12:16 AM     #2 (permalink)
Space for Sale! :p
 
eagle1's Avatar
 
Join Date: Oct 2001
Location: La Isla del Encanto
Posts: 5,836
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 February 12th, 2004, 12:47 AM     #3 (permalink)
Ultimate Member
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,977
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)
__________________

Last edited by lost-and-found : February 12th, 2004 at 12:55 AM.
lost-and-found is offline   Reply With Quote
Old February 12th, 2004, 12:56 AM     #4 (permalink)
Ultimate Member
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,977
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.

Last edited by lost-and-found : February 12th, 2004 at 12:58 AM.
lost-and-found is offline   Reply With Quote
Old February 12th, 2004, 01:01 AM     #5 (permalink)
Space for Sale! :p
 
eagle1's Avatar
 
Join Date: Oct 2001
Location: La Isla del Encanto
Posts: 5,836
Exactly what I meant!
Nice example for the main.
eagle1 is offline   Reply With Quote
Old February 12th, 2004, 05:22 PM     #6 (permalink)
Member
 
Join Date: Jun 2003
Location: Maine
Posts: 170
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 February 12th, 2004, 08:35 PM     #7 (permalink)
Ultimate Member
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,977
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.
lost-and-found is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2890)
Wireless Televisions. (8)
California Passes Anti-Flat-HDTV Le.. (39)
Obama the Muslim (14)
Is the PSU I received dead? (10)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
HIS HD5770 graphic card question (15)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
EVGA 9800 gtx help with finding a g.. (8)
New Computer wont recognize XP disc (7)
Recent Discussions
Wireless Televisions. (8)
windows 7 problem (2)
Point and Shoot Camera Suggestions. (0)
CPU fan stops spinning randomly (3)
wireless user (1)
Modern Warfare 2 freeze (12)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Partition Magic caused HDD problem (2)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Regular Build (3)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Have you switched yet? (84)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)
Wireless speakers for PC? (11)


All times are GMT -4. The time now is 10:38 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28