Menu solution

Hi im reletivly new to programming in C++ and this is my first attempt at trying to make a half decent project for myself. I have tried to incorperate the calling of functions , arithmatic, if statements and loops to help me gain a better understanding of the syntax and the language.
Here is my problem, i have tried to put in a menu option to the program ( its all in console for now) but when you run the code it seems to miss out the loop while statement all together, i think it might be the way i have tried to pass over the value for the global variable selection but i have no idea how to solve this as i have tried many different solutions to no prevail.

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
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

# define g 9.81
int selection = 0;
int menu()
{
    selection = a + b;
    cout << "1. The Vertical Velocity of an object after a determined amount of time" << endl;
    cout << endl;
    cout << "2. The vertical Displacement of an object after a determined amount of time" << endl;
    cout << endl;
    cout << "3. The Horozontal Displacement after a determined amount of time and off of\n   a certain height" << endl;
    cout << endl;
    cout << "4. Exit the program" << endl << endl;
    cout << "Please select the function you would like to perform : ";
    cin >> selection;
    return (selection);
}

double Vertv()
{
    cout << "Test Option 1 success ! ";
}

double Vertx()
{
    cout << "Test Option 2 success ! ";
}

double Horozx()
{
    cout << "Test Option 3 success ! ";
}

int end()
{
    cout << "Test Option 4 success ! ";
}

int main ()
{
    int n = 0;
    cout << "Welcome to the C++ Projectile Motion Calculator !" << endl;
    cout << endl;
    cout << "This Program can calculate many things about simple \nProjectile motion please select an option below "<< endl;
    cout << endl;
    cout << "---------------------------------------------------";
    cout << endl;
    do {
    if (selection = 1 )
    {
        n = 1;
        Vertv();
    }
    else if (selection = 2)
    {
        n = 1;
        Vertx();
    }
    else if (selection = 3)
    {
        n = 1;
        Horozx();
    }
    else if (selection = 4)
    {
        n = 1;
        end();
    }
    else
    {
        cout << "You have not entered a valid selection please try again" << endl;
        cout << "Please select the function you would like to perform : ";
        cin >> selection;
    }
    } while (n = 0);
       


    system("pause");
        return 0;
}


Any help would be much apprieciated
luckielordie
Comparison operator is not = , it's ==
so you better replace = with ==
Look my friend, i didn't understood exactly what you are trying to do,but i made some simple changes to your code.First of all your functions Vertv() ,Vertx() are declared as double,which means that they must return a double variable.You selected just to print something inside them,so you beter declared thes as void. Also since you have 4 choises i would suggest swithc instead of if else

take a look at this :

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
#include<iostream>
using namespace std;


void Vertv()
{
    cout << "Test Option 1 success ! \n";
}

void Vertx()
{
    cout << "Test Option 2 success ! \n";
}

void Horozx()
{
    cout << "Test Option 3 success ! \n";
}

void end()
{
    cout << "Test Option 4 success ! \n";
}


void menu()
{
    char choise;
    int n=0;
    
    
    do
    {
        cout<<"Give me a choise  \n";
        cout<<"a----> The Vertical Velocity of an object after a determined amount of time \n";
        cout<<"b----> The vertical Displacement of an object after a determined amount of time \n";
        cout<<"c----> The Horozontal Displacement after a determined amount of time and off of   a certain height \n\n";
        
        cout<<"choise:\n";
        cin>>choise;

        switch(choise)
        {
            case('a'):
                Vertv();
                n=1;

                break;
            case('b'):
                Vertx();
                n=1;

                break;
            case('c'):
                Horozx();
                n=1;

                break;
            default:
                cout << "\n You have not entered a valid selection please try again \n";
                cout << "Please select the function you would like to perform : \n";

                break;
        }
    }while(n!=1);

}



int main()
{
    menu();

    return 0;
}

Thanks guys, i got up first thing this morning and had a go at your solutions. The reason the functions Horozx, Vertx and Vertv we're doubles is that they will output a value when the code is finished but your right for the purpose of testing those phrases they should have been void.

Thankyou all, i hope to finish the rest of the code at some point today i'll post it somewhere so that you can all see the finished result
luckielordie
Topic archived. No new replies allowed.