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.
#include <iostream>
#include <string>
#include <cmath>
usingnamespace 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();
}
elseif (selection = 2)
{
n = 1;
Vertx();
}
elseif (selection = 3)
{
n = 1;
Horozx();
}
elseif (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;
}
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
#include<iostream>
usingnamespace 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