Kamikaze Badger
October 28th, 2004, 01:22 AM
Ok, after learning a bit more C++, I've decided to take another shot at the stresser program.
But, I've got two basic questions abou functions...
When declaring a function with a data type, do all arguments with data types have to be the same type as the function decleration? Or can they vary?
And also, can I have multiple functions in a single program? If so, how would I set them up?
Epison07
October 28th, 2004, 01:42 AM
Ok, Im not sure what a stresser program is...but I think I can help.
When declaring a data type, the arguments can vary. So you could have a void function with three int passed to it. Or a float function with three int passed to it. Declaring the type of fuction tells the computer which data type you will return. So if you do have a float function with three int passed to it, just make sure you are returning a float and not an int, or else it will give you an error.
Yes, you can have as many fuctions as you want. That is what is great about functions, they make your code neat and organized.
//Test
#include<iostream>
using namespace std;
void this_function(int, int);
float that_function(int, int);
int main()
{
float x;
this_function(1,2);
x = that_function(3,4);
cout<<x<<endl;
return 0;
}
void this_function(int a, int b)
{
int x;
x = a + b;
cout<<x<<endl;
return;
}
float that_function(int a, int b)
{
float x;
x = (a+b)*2;
return x;
}
I hope that helps.
-Ep
Kamikaze Badger
October 28th, 2004, 01:50 AM
You just answered my questions fully and in a way I can actually undersand :D. Thanks!
COOKIE FOR YOU! Cookie --> @
EDIT: And a Stresser program is something like Prime95 or Sandra. I'm coding a simple one along the lines of Sandra's method, which is floating point arithmetic. Right now it's command line based, but I hope to get a GUI on it when I learn more C++.