ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include<stdio.h>
#include<stdlib.h>
#define SIZE 100
int prog_enterd(int *,int);
int main()
{
int memory[SIZE]; //simulated memory
int mess;
int acc = 0;
int intructcounter;
int operationcode,operand;
int instruction;
int loop;
//print welcome message first
printf("\n\n");
printf("***Welcome to Simcom!***\n***Please enter your program one
instruction word at a time**\n***I will type the location number and a
question mark***\n***You then type the word for that
location***\n***Type the sentinal -99999 to stop entering your
program***\n");
mess = prog_enterd(memory,SIZE);
if ( mess == 0)
{
printf("You have run out of lines to enter programs or you are at the
end of memory\n");
exit (0);
}
else
{ printf("Great Program loading compleated\n");
}
printf("Program execution begins\n");
for (intructcounter =0; intructcounter != 43 && intructcounter
< 99 intructcounter++)
{
instruction = memory[intructcounter];
operationcode = instruction / 100;
operand = instruction % 100;
switch (operationcode)
{
case 10: scanf("%d", &memory[operand]); //read
break;
case 20: acc = memory[operand]; //load
break;
case 30: acc += memory[operand]; //add
break;
case 43: printf("Simcom exectution terminated\n"); //HALT
break;
case 11: printf("%d\n",memory[operand]; //write
break;
case 21: memory[operand] = acc; //store
break;
case 31: acc -= memory[operand]; //subtract
break;
case 32: acc /= memory[operand]; //devide
break;
case 33: acc *= memory[operand]; //multiply
break;
case 40: intructcounter = operand;
break;
case 41: if (acc < 0) intructcounter = operand;
break;
case 42: if (acc == 0) intructcounter = operand;
break;
}
}
printf("Program execution compleate\n");
printf("Memory dump information");
for (loop = 0; loop <= mess; loop++)
printf("%02d %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');
return 0;
}
int prog_enterd(int *mem, int size)
{
int count = 0;
do
{
printf("%02d ? ",count);
scanf("%d",&mem[count]);
printf("\n");
if (mem[count] == -99999)
return count - 1;
count++;
}
while (count < size);
return 0;
}
strange issue here it says i have a parse error before line 38 ((its in blue))
but i dont see it do any of you see it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.