How to write a c++ code in LaTeX with proper alignment?

I am providing more details about my question below:
I need to write this:

```
if(a==b):
    a=2
    b=2

```

I need to write this above code in exactly the same way I put it above.
But if I use the following code in LaTeX:

```
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\begin{document}

    if(a==b):
        a=2
        b=2

\end{document}

```

I am not getting my required output. Can someone please help me out on how to get the desired output with proper alignment?