I want to create a little "calculator" but I dont know how can I create.
My problem is, I have an input file (.txt) with codes:
acc +40
acc -14
nop +386
jmp +262
acc -4
nop +25
... the "acc" adds the number to my variable
the "jmp" is jump to the line (jmp +500 jump foward 500 line)
the "nop" dont do anything
and here is my code but not working (the acc is okay, but the jmp is not)
ifstream file("my.txt");
string cmd;
int num;
int var= 0;
int i = 0;
if(file.is_open())
{
while (file >> cmd >> num)
{
cout << "Var" << var<< endl;
cout << "Command: " << cmd << " Number: " << num<< " ----" << i <<" // Var: " << var<< endl;
++i;
if(cmd == "acc")
{
var= var+ num;
}
if(cmd == "jmp")
{
;
}
}
file.close();
}else {
cout << "error"<< endl;
cin.get();
}