Storing/Manipulating user input into array?

Hello everybody! This is my first post here and I am extremely new with C++ (and programming in general) so please be patient with me! I'm writing a program which will take a user input of 3 digit numbers (like 437, 543, etc.) and store them into an array (which is named "memory" in the code). However, the first digit will represent an opcode and the remaining two numbers will represent a numerical value or memory cell location in the array "memory". Below is the code I have written so far (which doesn't work)...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <fstream>

using namespace std;

int main (void)
{
    string name;
    char inputCardResponse;
    ifstream inFile;
    ofstream outFile;
    int memory [100][2] = {001};                //INPUT & CALC - array to represent SC's 100 cells of memory, sets the first
                                                //               spot to the value of 001
    int inputCard [16][2];                      //INPUT        - array to represent SC's 15 IC slots
    int outputCard [16][2];                     //OUTPUT       - array to represent SC's 15 OC slots
    int instructionRegister;                    //CALC         - int to represent SC's instruction register
    double accumulator;                         //CALC         - double int to represent SC's ACC
    int programCounter;                         //CALC         - int to represent SC's program counter
    
    
    
    cout << "Hello! Welcome to Simple Computer Version 1.0.\nWhat is your name? \n";
    getline(cin, name);
    cout << "Thank you for using my Simple Computer "<<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('-') << "Funtion" << 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? How does the loop end?
    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;
    
}


I was wondering if anybody could point me in the direction as to what sort of functions/operations I should research in order to execute the decoding of the user input. Also, I require the user to enter the starting value for the variable "programCounter". I want the value that the user inputs to represent the location in the array "memory" where their input will be stored/accessed from. Any sort of guidance would be appreciated!

Thanks!!
To split the input of three digits:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

using namespace std;

int main()
{
	// Three digits number:
	 
	int x = 364;
	
	cout << "\nThree digits number: " << x << '\n';
	
	// To find the first digit:
	
	int firstDigit = x / 100;
	cout << "\nFirstdigit = " << firstDigit << '\n';
	
	// To find the last two digits:
	
	int last2Digits = x % 100;
	
	cout << "\nLast 2 digits = " << last2Digits << '\n';

	return 0;
}
Three digits number: 364

Firstdigit = 3

Last 2 digits = 64


Last edited on
bump
Topic archived. No new replies allowed.