|
-
March 15th, 2013, 07:05 AM
#11
Re: Winsock Math Operations client \ server
 Originally Posted by tmcfadden
However, how is it I incorporate these variables into my mathOp function to actually perform the calculation?
Your approach to this problem is backwards, to be honest with you. You should start from the "inside-out", not from the "outside-in".
The first thing you should have done is write a function that takes two double arguments, an operation, and returns the answer. It doesn't matter where the arguments came from, whether it be from a server, the keyboard, an input file, or hard-coded values from a sample main() program.
Code:
#include <iostream>
double mathOp(double arg1, double arg2, char functionToDo)
{
switch (functionToDo)
{
case '*':
return arg1 * arg2;
}
return 0;
//...
}
int main()
{
std::cout << "The answer to 3 * 6 is " << mathOp(3, 6, '*');
}
The function above doesn't care where the numbers or operation came from. Then you test the daylights out of that function, replacing 3, 6, and the '*' with other numbers, operations, etc. to make sure it works correctly.
Once you have a simple main() program working, then and only then do you now consider "client / server", parsing input, etc. The function is in place, and now it's just a matter of taking the data from wherever it comes from, and supplying the data to the function.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; March 15th, 2013 at 07:11 AM.
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
|