Need Help with c++

I have been learning how to code in c++ for around a week and I have been working on a project. Within this project, I am having trouble stating my 3rd case within a switch, I am also wondering how to implant a loop so if you type “back”, I want to it go back to the beginning or go back to the past operation or project. Here is the code:


#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main ()

{

    char a;

    int password;



    cout << "enter password: " << endl;
    cin >> password;

    if (password == 4984)
    {
        cout << "Choose What you want to do" << endl;
        cout << "1 = calcator 2 = Game  3 = Test: ";
        cin >> a;
            switch (a)
                {
                case '1':

                   int r, d, q, y;

                    cout << "enter the oporator: ";
                    cin >> a;

                    cout <<"Enter the numbers: ";

                    cin >> r;
                    cin >> d;

                    switch (a)
                         {
                            case '+':
                                cout << r + d << endl;
                                break;
                            case '-':
                                cout << r - d << endl;
                                break;
                            case '*':
                                cout << r*d << endl;
                                break;
                            case '/':
                                cout << r/d << endl;
                                break;

                            }


                    case '2':
                           string a, b;
                    cout << "To start questionair enter yes:  ";
                    cin >> a;

                    if (a == "yes")
                        {
                        cout << "what is the captial of france:  ";
                        cin >> a;

                              if (a == "paris")
                                {
                                    cout << "correct!" << endl;
                                }
                                    else
                                    {
                                        cout << "Not correct" << endl;
                                    }

                                        cout << "What is the captital of alberta:  ";
                                        cin >> b;

                                        if (b == "edmonton")
                                        {
                                            cout << "correct!" << endl;
                                        }
                                            else
                                            {
                                                cout << "Not correct" << endl;
                                            }
                                                cout << "What is 5 - 7 =";
                                                cin >> b;
                                                if (b == "-2")
                                                {
                                                    cout << "Correct!" << endl;
                                                }
                                                    else
                                                    {
                                                        cout << "wrong" << endl;
                                                        break;
                                                    }
                                                    }

                                    case '3':
                                        string c, d;
                                        cout << "choose difficultly level: 1 = esay 2 = medium 3 = hard:   ";
                                            cin >> a;

                                            switch (a)
                                            {

                                                case '1':
                                                    cout << "po_k:   ";
                                                    break;
                                                case '2':

                                                    cout << "y_ot:     ";
                                                    break;

                                                case '3':
                                                    cout << "assu_e:    ";
                                                    break;


                                            }

                                            cout << "pick your letters:    ";
                                            cin >> a;
                                            switch (a)

                                            {
                                                case 'o':
                                                    cout << "good job! ";
                                                    break;

                                                case 'm':
                                                    cout << "nice ";
                                                    break;

                                                case 'r':
                                                    cout << "great job ";
                                                    break;

                                            }

                                            }


                                             }
                                            else
                                            {
                                                cout << "wrong passcode!";
                                            }
                                            }
#include
#include
#include
#include

how 2 use modules

Looks like you’re embedding a switch statement inside the if statement, and then an if statement inside of that.

It might be easier to clean up if you just did those all separately.

Write it all out with a flowchart or diagram first before coding it.

For example,

char a;

    int password;



    cout << "enter password: " << endl;
    cin >> password;

    if (password != 4984)
    {
       cout << "Sorry" << endl;
       return 0;
    }

That way, it checks if the password is right. If it isn’t (that != means not equal to), it will continue on.

Then you can do your next bit:

cout << "Choose What you want to do" << endl;
        cout << "1 = calcator 2 = Game  3 = Test: ";
        cin >> a;
            switch (a)
                {
                case '1':
                       calculator();
                case '2':
                       game();
                case 3:
                       test();
               }

and put your code for each of those inside its own function. You can create functions like this:

void calculator () 
     {

        put calculator code here

    }

So that whenever you call calculator(); it will do whatever is inside that function.

Does that make sense?

The other thing you should know, is that you can put code here in this forum by surrounding it will three tildes `

like this

```
code goes here
This is code too
example example
```

Will look like this:

code goes here
This is code too
example example