-
March 11th, 2013, 02:26 PM
#1
Passing data through a void function
Hey, first time posting here. I am new to C++ (day 2 since I started learning it) so bear with me.
Ok so my question is if I were to pass some data or values from the main() function through a void function (which main purpose is to display the data in a certain manner); how should one go about doing so?
For instance:
Code:
// example.cpp -- poorly written, just trying to learn
#include <iostream>
void format()
{
using namespace std;
cout << "Time: " << min << hrs << endl;
};
int main()
{
using namespace std;
int hrs;
cin hrs;
cin min;
format(); // call the void format to display them in a certain way
return 0;
}
Obviously this is really poorly written, and confusing for the user. My main goal is to learn how to pass through values to a void function.
Also a bit off-topic, but is there a downside to place "using namespace std;" outside a function say if out of 100 functions only 10 of them use it? Would it make the program slower/unstable in any way or is this something one could do without any downsides?
Please excuse my English if it is hard to understand - it's not my mother tongue.
- Heew
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|