Hey there guys I need your help as I do not fully understand the program source code below. This program will multiply two numbers without using the multiplication sign (*). I am confused with the highlighted part, the for loop part. Here it is:
#include <iostream>
#include <string>
using namespace std;
double productOf(double first, double second)
{
double product(0);
for (int i = 1; i <= second; i++)
product = product + first;
return product;
}
int main()
{
int first;
int second;
cin >> first;
cin >> second;
cout << productOf(first,second);
system("pause");
return 0;
}
I do not understand the use of the i variable in that for loop. Can someone please explain to me how it works? Thanks in advance to those who will help. :)