/*
    string_addition.cpp code for how to read in strings, and process them as numbers.

    See Nyhoff P228 for more details on strings class.
               
    http://www.cplusplus.com/reference/string/
    https://en.wikipedia.org/wiki/ASCII
*/

#include <iostream>           // Include cin / cout streams for input/output
#include <string>             // include string type
#include <cstdlib>            // exit
using namespace std;

int GetDigit(const string &s, int i)
{
   if (i<0)          // In this case we fail.
       {
          cout << "GetPos called with negative position!\n";
          exit(1);
       }

   if (i>s.length()) // In this case we also fail
       {
          cout << "GetPos called with a position that is longer than the string!!\n";
          exit(1);
       }

// s[i] is an ASCII character, '0' is the ASCII character zero, but it has the value 48.       
  return int(s[i])-int('0');
}


int main()
{         
   string n1,n2;                        // Strings of characters which we used to store the digits of our numbers

   cout << "Please enter n1=:";
   cin  >> n1;                          // read string from keyboard until space/enter
   cout << "Please enter n2=:";
   cin  >> n2;                          // read string from keyboard until space/enter

// This code just prints out all the digits of the two numbers   
   for (int i=0;i<n1.length();i++)
      {
         cout << "n1[" << i << "] is the digit " << GetPos(n1,i) << "\n";
      }

   for (int i=0;i<n2.length();i++)
      {
         cout << "n2[" << i << "] is the digit " << GetPos(n2,i) << "\n";
      }

// Here write the code to add the two numbers together digit by digit.
// NB digit=(d1+d2)%10  mente=(d1+d2)/10

   return 0;
}
