Provide dry run

As this was a lengthy code and some of the new concepts which were not taught in previous 4 lectures of string,I found myself unable to understand the code fully.

  1. what does ‘convertToInt’ do?
  2. pair<string, string> strpair[100] do?
    pls try to explain above two by example.
    waiting for your positive reply.
    Thank you
int convert_to_int(string s)
{
    int ans=0,p=1;
    for(int i=s.length()-1;i>=0;i--)
    {
        ans+=((s[i]-'0')*p);
        p=p*10;
    }
}

we have string s
suppose s=“123” now we want to convert it into integer 123

we iterate on the string take character one by one and make integer from it
first we get ‘3’ which is character so we have to convert it to integer
so we subtract it from ‘0’ so that we have integer
now we multiply 3 with its place value

when we come out of loop we got our number

strpair is an array but not of the type int or char
it’s type is pair<string,string>
means at every index we have pair of string and string

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like :heart:: and don’t forgot to mark doubt as resolved :grinning:

1 Like

Big help, thank you sir!