I am very new to C++ and appreciate all the help, so please be patient with me! I was tasked with writing a C++ program which essentially emulates a simple CPU.
My overall goal is to have the user input various 3 digit numbers into an array I have created called "memory". The array "memory" will have 100 available locations and the user is allowed to load their input into any available spots (the array is sized [100][2] because i want the last two digits to be treated as a single number).
The variable "programCounter" will represent the beginning location for where the user input will be stored within the array. So, for example, if the user inputs the value "20" for programCounter, then the user's input will be stored starting from the 21st location in the array and beyond, until their input is finished. What I have written below does not work and the loop for the user input into "memory" never ends. Is there another way to have the user input their values into the array, and then provide some sort of exit code to let the program know that the user is finished inputting?
Here is my code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main (void)
{
string name;
char inputCardResponse;
ifstream inFile;
ofstream outFile;
int memory [100][2] = {001}; // sets the value of the first memory spot to "001"
int inputCard [16][2];
int outputCard [16][2];
int instructionRegister;
double accumulator;
int programCounter;
cout << "Hello! Welcome to Simple Computer Version 1.0.\nWhat is your name? \n";
getline(cin, name);
cout << "Thank you for using my Simple Comuter "<<name<<"!\n";
cout << "Let's get started!\n";
cout << "Below is the table of Opcodes and their functions:";
cout << endl << endl;
{
cout << setw(9) << "| Opcode" << setw(20) << setfill('-') << "Function" << setw(12) << "|" << endl;
cout << setw(9) << "| ------" << setw(20) << setfill(' ') << "-------" << setw(12) << "|" << endl;
cout << setw(5) << "| 0_ _" << setw(20) << setfill('-') << "Input" << setw(14) << "|" << endl;
cout << setw(5) << "| 1_ _" << setw(21) << setfill('-') << "Output" << setw(13) << "|" << endl;
cout << setw(5) << "| 2_ _" << setw(18) << setfill('-') << "Add" << setw(16) << "|" << endl;
cout << setw(5) << "| 3_ _" << setw(23) << setfill('-') << "Subtract" << setw(11) << "|" << endl;
cout << setw(5) << "| 4_ _" << setw(22) << setfill('-') << "Load AC" << setw(12) << "|" << endl;
cout << setw(5) << "| 5_ _" << setw(23) << setfill('-') << "Store AC" << setw(11) << "|" << endl;
cout << setw(5) << "| 6_ _" << setw(19) << setfill('-') << "Jump" << setw(15) << "|" << endl;
cout << setw(5) << "| 7_ _" << setw(22) << setfill('-') << "Test AC" << setw(12) << "|" << endl;
cout << setw(5) << "| 8_ _" << setw(23) << setfill('-') << "Shift AC" << setw(11) << "|" << endl;
cout << setw(5) << "| 9_ _" << setw(19) << setfill('-') << "Halt" << setw(15) << "|" << endl;
}
cout << endl << endl;
//Input section
cout << "Please plan your program out. This emulator requires the user to enter a starting value";
cout << "for the program counter (typically cell 20 is chosen)\n";
cout << "When you are ready, please enter the starting cell you have chosen for the program counter: ";
cin >> programCounter; // Initializes the program counter value
cout << "Now that you have chosen a starting cell, please start entering your program: \n";
// This loop stores the user's program into the array named "memory". What happens if input<100??
for(;programCounter < 100; programCounter++)
{
cin >> memory[programCounter][2];
}
cout << "Do you have any information to store in the input card?\n";
cout << "(Please input uppercase Y for Yes or N for No \n";
cin.get(inputCardResponse);
if(inputCardResponse == 'Y')
{
cout << "There are 15 input slots available. Please keep this in mind when inputting: \n";
for (int inputCounter=0; inputCounter < 15; inputCounter++)
{
cin >> inputCard[inputCounter][2];
}
}
else{
cout << "Most programs require inputs.\n";
cout << "Please come back when you are ready with a file!\n";
}
return 0;
}