User talk:Superstitionfreeblog
Jump to navigation
Jump to search
HEY ! ! ! ! I said that it can't run. Just tell me what's wrong with my interpreter:
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int tape[65535];
int main()
{
ifstream fin;
fin.open("subleq.txt", ios::in);
if (!fin.is_open())
{
cout << "Failed to open SUBLEQ.TXT" << endl;
return -1;
}
cout << "Program:\n";
int cnt = 0;
int n;
char ch = ',';
do
{
fin >> n >> ch;
tape[cnt] = n;
cnt++;
cout << n << " ";
}
while(ch != ';');
cout << "\n";
fin.close();
system("pause");
int pc = 0;
cout << "\n-----------\n";
do
{
int a = tape[pc];
int b = tape[pc+1];
int c = tape[pc + 2];
int na,nb,nres;
if(a == -1){cin >> ch; na = ch;} else na = tape[a];
if(b == -1){nb = 0;} else nb = tape[b];
nres = na - nb;
if(b == -1){cout << (char)nres;} else tape[b] = nres;
if(nres <= 0) pc = c;
else pc += 3;
}
while(pc >= 0);
cout << "\n-----------\nThe Subleq program halts.";
while(true) cout;
}
while the file subleq.txt contains:
18,-1,3,33,0,6,34,0,9,32,0,-1,32,0,15,34,34,0,72,101,108,108,111,44,32,119,111,114,108,100,33,10,32,-1,0;
islptng 04:03, 16 October 2024 (UTC)
- I'll try to. I don't program in windows or C++. I am a little familiar with it though. I appreciate you sharing your code. I'll share mine with you once I get it reading files. Superstitionfreeblog (talk) 15:31, 16 October 2024 (UTC)