|
-
January 5th, 2010, 07:02 PM
#1
Probably a noobish question concerning functions()
Hello! Im very new to C++ but find it exciting and fun (so far, heh). I've run into a couple of problems that I've solved with either tutorials or forum threads. But to this latest problem I can't find a straight answer anywhere - perhaps because its simplicity? :P
Anyway, I need to know how to store two (or more) values in a function, and how I should manage to extract them from there, one by one. One value, no problems, but observe the very simple code example below;
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int function1(int value1, int value2);
int main(int nNumberofArgs, char* pszArgs[])
{
int sword = 15;
int armor = 10;
sword = sword *function1( ,sword); //Im guessing that I should put
armor = armor *function1(armor, ); //something in front of ,sword and something
//behind armor, here
cout <<"The sword value is: "<<sword<<endl;
cout <<"The armor value is: "<<armor<<endl;
system ("PAUSE");
return 0;
}
int function1(int value1, int value2)
{
value1 = 15; //this value is to be multiplied with "armor"
value2 = 25; //this value is to be multiplied with "sword"
return value1;
return value2;
}
What I want to do is to get value1 (=15) from function1() and multiply it with the "armor value", and the value2 (=25) from the same function multiplied with the "sword value". But I also need to be able to only extract one of the values from function1() in other parts of the code.
To keep it short, the function() is to act as a database for a few variables.
I'm probably doing it all wrong? Anyways, some help with the above suggestions or re-organisation of the code would be very helpful. Maybe functions isnt the way to go?
Thanks!
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
|