need some definitive comments please

hey everyone, im a beginner in c++. our professor gave a program and our assignment is to make an algorithm for this program. comments must also be inserted to describe each loops and functions. but i just dont get the program. i seriously need some help. thanks.

here's the program:

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//this program multiplies large numbers

#include <iostream>
#include <string>
#include <windows.h>
#define OVERFLOW 2 
#define ROW b_len         //we put so we can used as a dimension for arrays at global scope
#define COL a_len+b_len+OVERFLOW
using namespace std;

int getCarry(int num);
int num(char a); 
string mult(string a, string b);
void printResult(string a);

int main()

 {
    
string a,b;
char ans;




   do
     {
       system("cls");

       cout<<"\n           ---------------------------------------------------------"; 
       cout<<"\n           ------------------Banez, Juan Miguel---------------------";
       cout<<"\n           ----------------------Bernardo, Jeyo---------------------";
       cout<<"\n           ----------------Placido, James Alexon J.-----------------";
       cout<<"\n           ---------------------------------------------------------";


      cout<<"\n LLLL           AAA     RRRRRRRR      GGGGGGGG   EEEEEEEE";
      cout<<"\n LLLL         AAAAAAA   RRRR    RR    GGG        EEEE    ";
      cout<<"\n LLLL        AAA   AAA  RRRRRRR       GGG GGGG   EEEEEE  ";
      cout<<"\n LLLLLLLL    AAAAAAAAA  RRRR   RR     GGG    GG  EEEE    ";
      cout<<"\n LLLLLLLL    AAA   AAA  RRRR    RR    GGG GGGG   EEEEEEEE";

     cout<<"\n\n      ###   ###     XXXX     XXXX   IIII  EEEEEEEE   RRRRRRRR   ";
                 cout<<"\n     ###   ###        XXX   XXX     IIII  EEEE       RRRR    RR ";
     cout<<"\n   #############       XXXXXXX      IIII  EEEEEE     RRRRRRR    ";
     cout<<"\n   #############       XXXXXXX      IIII  EEEEEE     RRRR   RR  ";
     cout<<"\n    ###   ###         XXX   XXX     IIII  EEEE       RRRR   RR  ";
     cout<<"\n   ###   ###        XXXX     XXXX   IIII  EEEEEEEE   RRRR    RR ";   

     cout<<"\n\nEnter first digit: "; //prompt the user to enter the first group of numbers or Multiplier
     cin>>a;
     cout<<"\nEnter second digit: "; //prompt the user to enter the second group of numbers or Multiplicand
     cin>>b;
     cout<<"\n\nThe answer is: "<<endl;  //print the product of the two group
     printResult(mult(a,b));

     cout<<"\n\nDo you want to try again Y/N? ";
     cin>>ans;
     }while (ans=='Y');

    cin.get();cin.get();
    return 0;
}

int getCarry(int num)//function to separate the carried value from the partialproduct (num)
{
  int carry = 0;
  if(num>=10)
   {
    while(num!=0)
     {
      carry = num %10;
      num = num/10;
      }
  }
  else carry = 0;
  return carry;
            }
 
int num(char a)//this function will convert the char input to int input
{
  return int(a)-48; /*this formula was based from the ASCII table: http://www.asciitable.com/ */
}
 
string mult(string a, string b)
   {
    std::string ret;
    int a_len = a.length();
    int b_len = b.length();
    int mat[ROW][COL];
    for(int i =0; i<ROW; ++i)
       {
         for(int j=0; j<COL; ++j)
            {
              mat[i][j] = 0;
 
            }
      }
 
int carry=0, n,x=a_len-1,y=b_len-1;
for(int i=0; i<ROW; ++i) 
                 {
       x=a_len-1;
       carry = 0;
       for(int j=(COL-1)-i; j>=0; --j) 
          {
            if((x>=0)&&(y>=0)) 
              {
                n = (num(a[x])*num(b[y]))+carry;
                mat[i][j] = n%10;
                carry = getCarry(n);
              }
          else if((x>=-1)&&(y>=-1)) mat[i][j] = carry;
          x=x-1;
         }
       y=y-1;
    }
 
carry = 0;
int sum_arr[COL];
for(int i =0; i<COL; ++i) sum_arr[i] = 0;
for(int i=0; i<ROW; ++i) 
     {
       for(int j=COL-1; j>=0; --j)
         {
           sum_arr[j] += (mat[i][j]);
         }
    }
int temp;
for(int i=COL-1; i>=0; --i) 
     {
       sum_arr[i] += carry;
       temp = sum_arr[i];
     sum_arr[i] = sum_arr[i]%10;
    carry = getCarry(temp);
	  }
 

for(int i=0; i<COL; ++i) 
   {
     ret.push_back(char(sum_arr[i]+48));
   }
 
   while(ret[0]=='0')
     {
       ret = ret.substr(1,ret.length()-1);
     }

 return ret;
 }
 
void printResult(string a)
 {
    cout<<"\n";
    for(string::iterator i = a.begin(); i!=a.end(); ++i)
       {
         cout<<*i;
       }
 }
You want to know what this program is doing. Is that your question? If so, If I were you, I would load this up into Codeblocks or Visual studio and set a break point at the beginning of the program and just click next instruction or next line through out the entire program, and watch what all your variables are doing and watch your output in the terminal window.
Topic archived. No new replies allowed.