How would I get the name of the function a std::function<T> holds?
[IMG]http://i.imgur.com/Kmfb1ll.jpg[/IMG]
saveitem.savedata is a boost::variant.
It is exported:
[IMG]http://i.imgur.com/Jb8F6IX.jpg[/IMG]
Am I missing something important? Do I really need a seperate container that just holds the names?
You mean you want to somehow extract the string "TestEntity::ExraThink" from the boost::function?
Yeah, you're going to need to store this manually, since when the code gets compiled, the function will only be an address and boost::function does not store any meta-data about it.
You don't necessarily need another container; you could for example store a pair<string, function>.
[QUOTE=ZeekyHBomb;43115504]I think you want if(answer == yes), so it breaks out of the loop when the user typed yes.
Also, if the first message ("Hours worked: ") is the same as the message asking for input again, you can just move a single cout (instead of two, doing the same) to the top of the loop-body.[/QUOTE]
Should it be asking for the hours to be re-entered if i enter a yes, or a no?
The way it is now, with if(answer == yes) when i enter 'yes' it asks for hours worked, and if i type no it does it too. I'm not sure if i messed something up in the loop, so that when i type 'yes' it just goes ahead and does the math, instead of asking for a new answer if i type no.
[QUOTE=CRASHFORT;43116316]How would I get the name of the function a std::function<T> holds?
[IMG]http://i.imgur.com/Kmfb1ll.jpg[/IMG]
saveitem.savedata is a boost::variant.
It is exported:
[IMG]http://i.imgur.com/Jb8F6IX.jpg[/IMG]
Am I missing something important? Do I really need a seperate container that just holds the names?[/QUOTE]
Exported symbol names are there only for linking; they're not really meant for humans. Since you're using C++ they'd be mangled to all hell. To get them on Windows you'd probably load the library without linking, then parse the PE header manually, and unmangle the symbols. If you really wanted.
[QUOTE=ZeekyHBomb;43116478]You mean you want to somehow extract the string "TestEntity::ExraThink" from the boost::function?
Yeah, you're going to need to store this manually, since when the code gets compiled, the function will only be an address and boost::function does not store any meta-data about it.
You don't necessarily need another container; you could for example store a pair<string, function>.[/QUOTE]
[QUOTE=ThePuska;43118278]Exported symbol names are there only for linking; they're not really meant for humans. Since you're using C++ they'd be mangled to all hell. To get them on Windows you'd probably load the library without linking, then parse the PE header manually, and unmangle the symbols. If you really wanted.[/QUOTE]
Works wonders, didn't think of using std::pair.
[code]std::pair<std::string, std::function<void()>> Think;[/code]
[code]#define GetPfnName(a) #a
#define SetThink(a) Think = std::pair<std::string, std::function<void()>>(GetPfnName(a), std::bind(a, this));
[/code]
[code]SetThink(&TestEntity::ExtraThink);[/code]
[code]std::string str;
std::pair<std::string, std::function<void()>> pfn = boost::get<std::pair<std::string, std::function<void()>>>(saveitem.savedata);
str = pfn.first;
str.erase(str.begin());
entdata << str;[/code]
And of course fancying it up a little.
[code]typedef std::pair<std::string, std::function<void()>> EntityFuncPair;[/code]
I'm trying to convert screen-space to world-space in OpenGL. I have a tiled floor in my game, where everything at this point is on the X and Z axis (Y is 0). I have an orthogonal projection and a camera that rotates the floor. I want to convert my mouse coords back into world space. I am able to match up mouse coords to screen coords, what I mean is I have a tile of size 1x1, located at position 0,0. So, when I do the gl_position calculation, the resultant vector has the x and y values equal to that of my mouse. However, the z value is what I am unsure of how to attain. It is different and I am not sure where it is obtained, but it prevents me from going backwards with my mouse values to get the x and y values of the tile. How is this Z value attained?
If what I wrote doesn't make sense, maybe this example will help illustrate what I mean
[cpp]glm::vec4 pos = VP*glm::vec4(1,0,1,1);
double mouseX, mouseY;
//get the mouse coords and then transform them.
glfwGetCursorPos(window, &mouseX, &mouseY);
x = (x*2/1024-1);
y = ((768-y)/768*2-1);
//the following are true when the mouse is hovering over the bottom right hand corner of the tile in question
pos.x == x;
pos.y == y;
//However I cannot do this:
glm::vec4 realpos = glm::inverse(VP) * glm::vec4(x, 0, y, 1);
//because then this is not true
realpos.x == x;
realpos.y == y;[/cpp]
IIrc, the graphics pipeline divides part of the vector by the w component after all transformations are applied, so you can't go back using matrix transformations alone if you start with a frame buffer pixel.
I thought that was only with perspective projections?
I just downloaded visual c++ 2010 on a new laptop and I'm having a problem where when I go back to edit code a grey box appears over the next character and deletes it. I've fixed this before but it was a long time ago, can someone please help me? Sorry about the question.
[QUOTE=Ben Katz;43119304]I just downloaded visual c++ 2010 on a new laptop and I'm having a problem where when I go back to edit code a grey box appears over the next character and deletes it. I've fixed this before but it was a long time ago, can someone please help me? Sorry about the question.[/QUOTE]
Press insert.
Thanks, maybe I'll be back with a question that isn't stupid.
[editline]8th December 2013[/editline]
How do I compile?
:v:
F5 to compie and debug, Build -> Build Solution to just compile the code
I was trying to make a joke, sorry man.
[QUOTE=Ben Katz;43119304]I just downloaded visual c++ 2010 on a new laptop and I'm having a problem where when I go back to edit code a grey box appears over the next character and deletes it. I've fixed this before but it was a long time ago, can someone please help me? Sorry about the question.[/QUOTE]
If it's any consolation, i was going the same thing for a little while today. Finally i hit insert and just sat there cursing myself for all the re-typing i had made myself do.
How come the order of matrix multiplication is different between DirectX and OpenGL?
DIRECTX:
[CODE]
XMMATRIX matWorld = matScaling * matRotation * matTranslation;
XMMATRIX matWVP = matWorld * matView * matProjection;
[/CODE]
OPENGL:
[CODE]
auto matWorld = matTranslate * matRx * matRy * matRz * matScale;
auto matWVP = matProjection * matView * matWorld;
[/CODE]
Also, is there some kind of standard in the order of multiplying your Rotation matrices?
[QUOTE=Sergesosio;43120947]How come the order of matrix multiplication is different between DirectX and OpenGL?
DIRECTX:
[CODE]
XMMATRIX matWorld = matScaling * matRotation * matTranslation;
XMMATRIX matWVP = matWorld * matView * matProjection;
[/CODE]
OPENGL:
[CODE]
auto matWorld = matTranslate * matRx * matRy * matRz * matScale;
auto matWVP = matProjection * matView * matWorld;
[/CODE]
Also, is there some kind of standard in the order of multiplying your Rotation matrices?[/QUOTE]
The matrices are transposed between D3D and OpenGL. The multiplication rule is the same, but the flipped matrices result in the difference.
OpenGL seems to use the common one, D3D's is flipped against what I'd use.
[editline]9th December 2013[/editline]
[QUOTE=JohnStamosFan;43119538]If it's any consolation, i was going the same thing for a little while today. Finally i hit insert and just sat there cursing myself for all the re-typing i had made myself do.[/QUOTE]
This happened to me in primary school, we retyped the document about 2.5 times.
[editline]9th December 2013[/editline]
[QUOTE=WTF Nuke;43119009]I thought that was only with perspective projections?[/QUOTE]
Oh, sorry, I think I skipped that part.
You probably don't need the z-value, only the x/y coords in relation to the anchor point of your transformation.
I hope the equality operator is only there to illustrate the issue, it's relatively unlikely to hit the precise starting point because of floating point errors I think.
[QUOTE=JohnStamosFan;43117372]Should it be asking for the hours to be re-entered if i enter a yes, or a no?
The way it is now, with if(answer == yes) when i enter 'yes' it asks for hours worked, and if i type no it does it too. I'm not sure if i messed something up in the loop, so that when i type 'yes' it just goes ahead and does the math, instead of asking for a new answer if i type no.[/QUOTE]
Certainly weird. Are you sure that yes compares equal to the string "yes"? answer is of type std::string, right?
[QUOTE=Tamschi;43115680]You put that line into the form, after you create the logic instance or get a reference to it or whatever (only run it once near the start). This line gives a reference to the form to [I]lInst[/I], the process is called subscribing to the event.
If you set a breakpoint in the forms [I]Update[/I] method or step into [I]Updated();[/I], you will see that OnUpdate calls this method [U]through the event's delegate field[/U] (part of what the event is a shorthand for).
Where do the 5 second intervals originate from currently? It would help if you posted more of your program. (I should be able to give you a good example if you post your logic class.)
If [I]lInst[/I] lives longer than the form, make sure to remove the subscription with -= when the latter closes or it will linger in memory and continue to receive notifications.[/QUOTE]
Here's the entire logic class
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace Projekt_Produkt_December
{
public class Logic
{
Timer t = new Timer();
Data dInst = new Data();
private int counter;
public event Action Updated;
public Logic()
{
timerTick(null, null);
t.Tick += new EventHandler(timerTick);
}
public void timerTick(object sender, EventArgs e)
{
t.Interval = 1000;
t.Enabled = true;
if (counter >= 10)
{
counter = 0;
//Opdatér dataGridView i E_DETEKTOR_INTERFACE FORMEN!!
}
else
{
counter++;
}
}
public string getVersion()
{
return dInst.getVersion();
}
public string getLastUpdate()
{
return dInst.getLastUpdate();
}
public DataSet getDataSetCitizen()
{
return dInst.getDataSetCitizen();
}
public DataSet getDataSetSpecificCitizen(string cpr)
{
return dInst.getDataSetSpecificCitizen(cpr);
}
public DataSet getDataSetTemporary()
{
return dInst.getDataSetTemporary();
}
public DataSet getDataSetEKGMAELING(string cpr)
{
return dInst.getDataSetEKGMAELING(cpr);
}
public Measure getMeasurePrivate(string maaleid)
{
return dInst.getMeasurePrivate(maaleid);
}
public Measure getMeasurePublic(string ekgmaaleid, string borger_fornavn, string borger_efternavn)
{
return dInst.getMeasurePublic(ekgmaaleid, borger_fornavn, borger_efternavn);
}
public void saveToPublic(Measure tempMeasure, string a_f, string a_e, string a_m, string a_o, string a_k)
{
dInst.saveToPublic(tempMeasure,a_f,a_e,a_m,a_o,a_k);
}
public void deleteFromTemporary(Measure tempMeasure)
{
dInst.deleteFromTemporary(tempMeasure);
}
protected void OnUpdated()
{
if (Updated != null) Updated();
}
private void Listener() //Lige nu bliver den ikke kaldt. Vi skal have den til at lytte, give en string til logik laget, som viser den i en GUI.
{
var PORT_NO = 5000;
var SERVER_IP = "127.0.0.1"; // Vi lytter til os selv håhå
IPAddress localAdd = IPAddress.Parse(SERVER_IP);
TcpListener listener = new TcpListener(localAdd, PORT_NO);
listener.Start();
while (true)
{
dInst.listen(listener);
}
}
}
}
[/code]
Here's the code for the form
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Projekt_Produkt_December
{
public partial class E_Detektor_Interface : Form
{
DataSet dsCitizen = new DataSet(); //Information der tilføjes til borger/patient tabellen til venstre.
DataSet dsTemp = new DataSet(); //Information der tilføjes til nye målinger tabellen til højre.
Logic lInst; //Instans af logik laget som vi får overført fra en forrig form. Ikke en ny instans.
DataGridViewButtonColumn bCitizen = new DataGridViewButtonColumn(); //Knapper til venstre
DataGridViewButtonColumn bTemp = new DataGridViewButtonColumn(); //Knapper til højre
Form parent;
string a_f;
string a_e;
string a_m;
string a_o;
public E_Detektor_Interface(string fornavn, string efternavn, string medarbejdernr, string organisation, Form LogIn, Logic l)
{
a_f = fornavn;
a_e = efternavn;
a_m = medarbejdernr;
a_o = organisation;
parent = LogIn;
lInst = l;
InitializeComponent();
label3.Text = lInst.getVersion();
//Datagridview settings:
dataGridView1.Columns.Add(bCitizen); //Tilføj knapperne til deres respektive dataGridViews.
dataGridView1.Columns[0].Width = 50;
dataGridView1.RowHeadersVisible = false;
dataGridView2.Columns.Add(bTemp);
dataGridView2.Columns[0].Width = 50;
dataGridView2.RowHeadersVisible = false;
dataGridViewUpdate(); //Tilføj data!
dataGridView1.Columns[1].Width = 150;
dataGridView1.Columns[2].Width = 215;
dataGridView1.Columns[3].Width = 75;
lInst.Updated += Update;
}
private void dataGridViewUpdate()
{
dsCitizen.Clear();
dsTemp.Clear();
dataGridView1.DataSource = null;
dataGridView2.DataSource = null;
dsCitizen = lInst.getDataSetCitizen();
dsTemp = lInst.getDataSetTemporary();
dataGridView1.DataSource = dsCitizen.Tables[0];
dataGridView2.DataSource = dsTemp.Tables[0];
}
private void WindowsFormClosing(object sender, FormClosingEventArgs e)
{
parent.Close(); //LogIn formen var kun skjult da vi åbnede denne form, E-Detektor Interface. Vi bliver nød til at lukke LogIn formen for at terminere programmet.
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
string cprnr = dsCitizen.Tables[0].Rows[e.RowIndex][2].ToString();
EPJ form = new EPJ(cprnr, lInst);
form.Show();
}
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
string ekgmaaleid = dsTemp.Tables[0].Rows[e.RowIndex][2].ToString();
New_Measure form = new New_Measure(ekgmaaleid, lInst, a_f,a_e,a_m,a_o);
form.Show();
}
}
}
}
[/code]
[editline]9th December 2013[/editline]
sorry for pagestretch
Anyone know of a powerful and well structured UI library for C++?
[QUOTE=war_man333;43124916]Here's the entire logic class
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace Projekt_Produkt_December
{
public class Logic
{
Data dInst = new Data();
private int counter;
public event Action Updated;
// You really should either expose dInst or change these to properties.
// Using explicit get...() methods is pretty awful, properties were invented to avoid this.
// Exposing dInst is better though, you should never have to write forwarders like this.
public string getVersion()
{
return dInst.getVersion();
}
public string getLastUpdate()
{
return dInst.getLastUpdate();
}
public DataSet getDataSetCitizen()
{
return dInst.getDataSetCitizen();
}
public DataSet getDataSetSpecificCitizen(string cpr)
{
return dInst.getDataSetSpecificCitizen(cpr);
}
public DataSet getDataSetTemporary()
{
return dInst.getDataSetTemporary();
}
public DataSet getDataSetEKGMAELING(string cpr)
{
return dInst.getDataSetEKGMAELING(cpr);
}
public Measure getMeasurePrivate(string maaleid)
{
return dInst.getMeasurePrivate(maaleid);
}
public Measure getMeasurePublic(string ekgmaaleid, string borger_fornavn, string borger_efternavn)
{
return dInst.getMeasurePublic(ekgmaaleid, borger_fornavn, borger_efternavn);
}
public void saveToPublic(Measure tempMeasure, string a_f, string a_e, string a_m, string a_o, string a_k)
{
dInst.saveToPublic(tempMeasure,a_f,a_e,a_m,a_o,a_k);
}
public void deleteFromTemporary(Measure tempMeasure)
{
dInst.deleteFromTemporary(tempMeasure);
}
protected void OnUpdated()
{
if (Updated != null) Updated();
}
private void Listener() //Lige nu bliver den ikke kaldt. Vi skal have den til at lytte, give en string til logik laget, som viser den i en GUI.
{
var PORT_NO = 5000;
var SERVER_IP = "127.0.0.1"; // Vi lytter til os selv håhå
IPAddress localAdd = IPAddress.Parse(SERVER_IP);
TcpListener listener = new TcpListener(localAdd, PORT_NO);
listener.Start();
while (true)
{
dInst.listen(listener);
OnUpdated(); //This runs after each connection, right?
}
}
}
}
[/code]
Here's the code for the form
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Projekt_Produkt_December
{
public partial class E_Detektor_Interface : Form
{
DataSet dsCitizen = new DataSet(); //Information der tilføjes til borger/patient tabellen til venstre.
DataSet dsTemp = new DataSet(); //Information der tilføjes til nye målinger tabellen til højre.
Logic lInst; //Instans af logik laget som vi får overført fra en forrig form. Ikke en ny instans.
DataGridViewButtonColumn bCitizen = new DataGridViewButtonColumn(); //Knapper til venstre
DataGridViewButtonColumn bTemp = new DataGridViewButtonColumn(); //Knapper til højre
Form parent;
string a_f;
string a_e;
string a_m;
string a_o;
public E_Detektor_Interface(string fornavn, string efternavn, string medarbejdernr, string organisation, Form LogIn, Logic l)
{
a_f = fornavn;
a_e = efternavn;
a_m = medarbejdernr;
a_o = organisation;
parent = LogIn;
lInst = l;
InitializeComponent();
label3.Text = lInst.getVersion();
//Datagridview settings:
dataGridView1.Columns.Add(bCitizen); //Tilføj knapperne til deres respektive dataGridViews.
dataGridView1.Columns[0].Width = 50;
dataGridView1.RowHeadersVisible = false;
dataGridView2.Columns.Add(bTemp);
dataGridView2.Columns[0].Width = 50;
dataGridView2.RowHeadersVisible = false;
dataGridViewUpdate(); //Tilføj data!
dataGridView1.Columns[1].Width = 150;
dataGridView1.Columns[2].Width = 215;
dataGridView1.Columns[3].Width = 75;
// turns out Update() already exists. (Whoops :v)
// You have to use your own method obviously.
// Calling the method with Invoke causes it to run on the display thread instead of the server's.
// This is blocking, you could use BeginInvoke but then you'd need synchronization/a mutex in the Data instance.
lInst.Updated += () => dataGridView1.Invoke(dataGridViewUpdate);
}
private void dataGridViewUpdate()
{
dsCitizen.Clear();
dsTemp.Clear();
dataGridView1.DataSource = null;
dataGridView2.DataSource = null;
dsCitizen = lInst.getDataSetCitizen();
dsTemp = lInst.getDataSetTemporary();
dataGridView1.DataSource = dsCitizen.Tables[0];
dataGridView2.DataSource = dsTemp.Tables[0];
}
private void WindowsFormClosing(object sender, FormClosingEventArgs e)
{
lInst.Updated += Update; // Important! If you don't do this half-dead forms will haunt you.
parent.Close(); //LogIn formen var kun skjult da vi åbnede denne form, E-Detektor Interface. Vi bliver nød til at lukke LogIn formen for at terminere programmet.
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
string cprnr = dsCitizen.Tables[0].Rows[e.RowIndex][2].ToString();
EPJ form = new EPJ(cprnr, lInst);
form.Show();
}
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
string ekgmaaleid = dsTemp.Tables[0].Rows[e.RowIndex][2].ToString();
New_Measure form = new New_Measure(ekgmaaleid, lInst, a_f,a_e,a_m,a_o);
form.Show();
}
}
}
}
[/code]
[editline]9th December 2013[/editline]
sorry for pagestretch[/QUOTE]
I threw out the timer, if [code]dInst.listen(listener);[/code] returns after processing a message this will trigger the event and update the form.
The whole Logic class is completely unnecessary though, move the event into Data and only call it if there's really a change and replace the get methods with [I]proper properties[/I].
You can use Data directly in the form and your server loop can start from a single (inline) method somewhere.
[editline]9th December 2013[/editline]
[code]lInst.Updated += Update; // Important! If you don't do this half-dead forms will haunt you.[/code] has to be [code]lInst.Updated -= () => dataGridView1.Invoke(dataGridViewUpdate);[/code]
The compiler turns the two lambdas into the same method which is why you can unsubscribe like this.
I don't know whether that is an implementation detail though, if you want to make absolutely sure then use an instance method instead of the lambda.
[QUOTE=war_man333;43124916]Here's the entire logic class...[/QUOTE]
Couldn't edit this post for some reason.
Wanted to add: It's 10 seconds, not 5 seconds. I just forgot!
[code]lInst.Updated -= () => dataGridView1.Invoke(dataGridViewUpdate);[/code]
What does the -= mean? The parenthesis? The =>?
Also by using the above code I'm getting
[code]Error 3 The best overloaded method match for 'System.Windows.Forms.Control.Invoke(System.Delegate, params object[])' has some invalid arguments C:\Users\Mathias\Documents\Lektier\IHA\3. Semester\Projekt\Projekt Produkt December\Projekt Produkt December\E-Detektor Interface.cs 49 36 Projekt Produkt December[/code]
and also
[code]Error 4 Argument 1: cannot convert from 'method group' to 'System.Delegate' C:\Users\Mathias\Documents\Lektier\IHA\3. Semester\Projekt\Projekt Produkt December\Projekt Produkt December\E-Detektor Interface.cs 49 57 Projekt Produkt December
[/code]
maybe I'm just way in over my head and not understanding anything at all.
Hey people, its not really programming but didn't know where else to ask!
Has anyone here been for a university interview (more specifically, oxford as their interview style is quite unique)? and if so, has anyone got some tips / topics to revise. Iv'e read the guide booklet and have two practice interviews set up..but first hand experience is great.
I see the point with removing the timer.
How do you refer to an event in the data-class if I want to refer to it from a form?
Should I make some horrible class that you don't like in the logic layer that returns an event? ;)
shit my automerge
[QUOTE=war_man333;43126920]I see the point with removing the timer.
How do you refer to an event in the data-class if I want to refer to it from a form?
Should I make some horrible class that you don't like in the logic layer that returns an event? ;)
shit my automerge[/QUOTE]
Message me on steam, i added you (Cartmanium.dll), i wanted to help you with this stuff but i never happen to message you when you're online.
[QUOTE=ZeekyHBomb;43122139]Certainly weird. Are you sure that yes compares equal to the string "yes"? answer is of type std::string, right?[/QUOTE]
Sorry for the delayed response.
But, yeah. Should be a string.
I'll check. Screw it. I'll just post the whole code, maybe that'll make it a bit easier.
[code]
//Aaron White
//*PROJECT #4*
//*Makea big crazy mess that turns numbers into magic and data.*
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void Pause ()
{//freezes screen
char junk;
cout <<endl << endl << "Press some keys followed by the Enter key to continue...";
cin.ignore();
cin.get(junk);
//end pause
}
int main()
{ //MAIN BODY
float fedTaxRate;
float stateTaxRate;
float GetPay;
float GetHrs;
float GetRate;
float CalcFICA;
float CalcFedTax;
float FICATaxRate;
float CalcStateTax;
float PrintStub;
float OTpay;
float OTTime;
float biWeekly;
string name;
string yes;
string no;
string answer;
//set the constant values
FICATaxRate = .0765;
fedTaxRate = .220;
stateTaxRate = .12;
//input from keyboard
cout << "Employee Name: ";
cin >> name;
cout << "Hourly Rate (Example: 15.00):$";
cin >> GetRate;
if((GetRate < 5.50) || ( GetRate > 200.00))//make sure to check and see if pay is less than 5.50, or greater than 200.00
{
cout << "Hourly Rate is not compatable." << endl << "Choose a number between $5.50 and 200.00." <<endl;
return(0);
}
else
{}
cout << "Hours worked: " << flush;
while(true)
{
cin >> GetHrs;
if(GetHrs <= 60)
{
break;
}
cout << "Hours worker is greater than 60." << endl << "Need user override. Type 'yes' or 'no'. " << endl;
cin >> answer;
if( answer == yes)
{
break;
}
//... ask again (only ask, the loop-body will get input again)
cout << "Hours worked: ";
}
cout << endl << endl << endl;
OTTime = GetHrs - 40;
OTpay = ((OTTime * GetRate) * 1.50);
/*test output
cout << "Name is: " << name << "Hourly Rate is: " << GetPay << "Hours Worked is: " << GetHrs;
Works*/
//display results
//Calculations
if(GetHrs <= 40)
{
GetPay = GetHrs * GetRate;
}
else
{
GetPay = OTpay + ( (GetHrs-OTTime) * GetRate);
}
// tax calculations
CalcFICA = GetPay * FICATaxRate;
CalcFedTax = GetPay * fedTaxRate;
CalcStateTax = GetPay * stateTaxRate;
PrintStub = GetPay - CalcFICA - CalcFedTax - CalcStateTax;
//output statements. set precious at 2 to show last 2 decimals.
cout << name << " made " << fixed << setprecision(2) << setw(25) << "$" << GetPay << endl << endl;
cout << "FICA: " << fixed << setprecision(2) << setw(31) << "$" << CalcFICA << endl << endl;
cout << "Federal: " << fixed << setprecision(2) << setw(27) << "$" << CalcFedTax << endl << endl;
cout << "State: " << fixed << setprecision(2) << setw(30) << "$" << CalcStateTax << endl << endl;
cout << "-------------------------------------------" << endl;
if(PrintStub > 10000.00)
{
cout << PrintStub << " is out of normal range." <<endl;
}
else
{
cout << "Net Pay: " << fixed << setprecision(2) << setw(27) << "$" << PrintStub << endl;
}
Pause();
return(0);
}
[/code]
:edit:
Some of the names are dumb/non-descriptive, but he specified some we absolutely had to use, but not in which part of the code.
Both strings yes and no are not set. They're default-constructed to the empty string "".
You should do string yes = "yes" or just use "yes" instead of a variable for that purpose (probably less confusing that having to look up whether the string yes actually contains "yes").
Alright guys, I have a problem that's driving me insane.
As a school project I'm building a Bitcoin arbitrage bot, written in node, targeted at the exchange website campbx.com
Node's synchronous nature means that some processes are being run faster than I want them to. In simple pseudocode, I want to:
[B]get the latest buy price
buy at the latest buy price[/B]
The problem is that the second function executes before the first one, which causes the program to buy at an undefined price.
I researched control flow, and decided async's series functionality was the best way to go.
My lack of node experience is resulting in the following code being run synchronously:
[code]var CampBX = require('campbx')
CampBXAccount = new CampBX("censored username lol", "censored password lol")
async = require('async')
BuyPrice = 0
start = function() {
console.log('Starting...')
};
getBuyPrice = function() {
CampBXAccount.ticker(function(err, data){
BuyPrice = data["Best Bid"];
});
};
buy = function() {
CampBXAccount.tradeEnter('QuickBuy', 0.1, BuyPrice, function(err, data){
if (err) {
throw err;
}
});
};
async.series([start, getBuyPrice(), buy()]);[/code]
If anyone can shed any light on my situation, I'd be forever grateful.
[QUOTE=Quincy.;43128362]Alright guys, I have a problem that's driving me insane.
As a school project I'm building a Bitcoin arbitrage bot, written in node, targeted at the exchange website campbx.com
Node's synchronous nature means that some processes are being run faster than I want them to. In simple pseudocode, I want to:
[B]get the latest buy price
buy at the latest buy price[/B]
The problem is that the second function executes before the first one, which causes the program to buy at an undefined price.
I researched control flow, and decided async's series functionality was the best way to go.
My lack of node experience is resulting in the following code being run synchronously:
[code]var CampBX = require('campbx')
CampBXAccount = new CampBX("censored username lol", "censored password lol")
async = require('async')
BuyPrice = 0
start = function() {
console.log('Starting...')
};
getBuyPrice = function() {
CampBXAccount.ticker(function(err, data){
BuyPrice = data["Best Bid"];
});
};
buy = function() {
CampBXAccount.tradeEnter('QuickBuy', 0.1, BuyPrice, function(err, data){
if (err) {
throw err;
}
});
};
async.series([start, getBuyPrice(), buy()]);[/code]
If anyone can shed any light on my situation, I'd be forever grateful.[/QUOTE]
I don't know node or JS well, buy why are you passing the function `start` itself but the return values of `getBuyPrice` and `buy`? That is, `getBuyPrice` is a variable holding a function, but `getBuyPrice()` would be whatever that function returned (which itself does not appear to be another function, so async.series probably can't make heads or tails of it.
[editline]9th December 2013[/editline]
[code]
$ node
> buy = function() { };
[Function]
> buy
[Function]
> buy()
undefined
>
[/code]
[QUOTE=Rayjingstorm;43128455]I don't know node or JS well, buy why are you passing the function `start` itself but the return values of `getBuyPrice` and `buy`? That is, `getBuyPrice` is a variable holding a function, but `getBuyPrice()` would be whatever that function returned (which itself does not appear to be another function, so async.series probably can't make heads or tails of it.
[editline]9th December 2013[/editline]
[code]
$ node
> buy = function() { };
[Function]
> buy
[Function]
> buy()
undefined
>
[/code][/QUOTE]
so, if I make getBuyPrice return BuyPrice, then pass getBuyPrice as a parameter in buy?
[editline]10th December 2013[/editline]
i'm in way too deep with this
i don't know what the fuck i'm doing
[QUOTE=Quincy.;43128662]so, if I make getBuyPrice return BuyPrice, then pass getBuyPrice as a parameter in buy?[/QUOTE]
No, that's not exactly what I mean.
Let's say you define a function:
[code]
var foo = function() { ... };
[/code]
now the identifier `foo` refers to a variable, which holds a function (I don't actually know the terminology for JS, but in most statically compile languages you would have to have a pointer to function and it would be referred to as a 'callback' because you are asking a function to 'call you back' through the function, but I digress).
If you now use the identifier `foo` (notice there are no parenthesis following it) you refer to [I]the function itself[/I], as an entity which is callable. If you then add parenthesis, i.e. `foo()`, you are in fact [I]calling[/I] the function to which `foo` refers and so are refering to whatever it returns.
In your case, both functions (`getBuyPrice` and `buy`) return [I]nothing[/I], that is to say they only have [I]side-effects[/I] and that is their purpose.
When you call async.serial([...]) you are asking it to call each of the elements of the list you pass [I]in order[/I] and do nothing with their return values. However, you are writing:
[code]
async.series([start, getBuyPrice(), buy()]);
[/code]
with the parenthesis present on the last two methods (the ones you really care about). This means the functions are called in place, [I]before[/I] async.series() even sees them. Because both functions return nothing, async.series() sees a list like this:
[code]
[[Function start], undefined, undefined]
[/code]
when, in fact, you probably intend for it to see something like:
[code]
[[Function start], [Function getBuyPrice], [Function buy]]
[/code]
I don't want to tell you the correct form of the line, because I think you should understand the error because it is a subtle but important one that will most certainly crop up again if you don't figure it out now. If you need more help, don't be afraid to ask, but I'm not going to just tell you the answer.
Sorry, you need to Log In to post a reply to this thread.