the objective of my code is to take user input of variables and figure out which equation to use then spit out the appropriate answer to the variable that the user wants to know, what seems to be happening is the acceleration(notibly the first equation function) is steeling the inputs and is kind of ignoring my && constraints. its not a very long program but there is a lot of repetitive code, also i am extremely new to coding so any and all advice is more than appreciated
#include <iostream>
usingnamespace std;
#include <math.h>
int keepgoing = true;
int main()
{
while (keepgoing == true)
{
cout <<"Hi what variable would you like to find"<< endl;
cout<<"a = acceleration"<<endl<<"t = time"<<endl;
cout<<"V = velocity"<<endl<<"Vo = initial velocity"<<endl;
cout<<"X = distance"<<endl<<"Xo = initial distance"<<endl;
string response;
cin >>response;
cout <<"if you do not know a variable please put no or n"<<endl;
cout <<"do you know a = ?"<<endl;
float a;
cin >>a;
if (cin.fail()){
cin.clear();
cin.ignore(999,'\n');
a = (NULL);
}
cout <<"do you know t = ?"<<endl;
float t;
cin >>t;
if (cin.fail()){
cin.clear();
cin.ignore(999,'\n');
t = (NULL);
}
cout <<"do you know V = ?"<<endl;
float V;
cin >>V;
if (cin.fail()){
cin.clear();
cin.ignore(999,'\n');
V = (NULL);
}
cout <<"do you know Vo = ?"<<endl;
float Vo;
cin >>Vo;
if (cin.fail()){
cin.clear();
cin.ignore(999,'\n');
Vo = (NULL);
}
cout <<"do you know X = ?"<<endl;
float X;
cin >>X;
if (cin.fail()){
cin.clear();
cin.ignore(999,'\n');
X = (NULL);
}
cout <<"do you know Xo = ?"<<endl;
float Xo;
cin >>Xo;
if (cin.fail()){
cin.clear();
cin.ignore(999,'\n');
Xo = (NULL);
}
if (response == "a"||"A" && (V!=NULL) &&(Vo!=NULL) && (t!=NULL))
{
a = ((V-Vo)/t);
cout.precision(5);
cout <<"a = ((V-Vo)/t);"<<endl;
cout <<" acceleration is '"<<a<<"'"<<endl;
a = (NULL);
X = (NULL);
Xo = (NULL);
V = (NULL);
Vo = (NULL);
t = (NULL);
system("pause");
system("ClS");
}
elseif ((response == "a"||"A") && (X!=NULL) && (Xo!=NULL) && (Vo!=NULL) && (t!=NULL))
{
a = ((2*(X-Xo-Vo*t))/(t*t));
cout.precision(5);
cout <<" a = ((2*(X-Xo-Vo*t))/(t*t))"<<endl;
cout <<" acceleration is '"<<a<<"'"<<endl;
a = (NULL);
X = (NULL);
Xo = (NULL);
V = (NULL);
Vo = (NULL);
t = (NULL);
system("pause");
system("ClS");
}
elseif ((response == "a"||"A") && (X!=NULL) && (Xo!=NULL)&&(Vo!= NULL) && (V!=NULL))
{
a = ((V*V-Vo*Vo)/(2*X-2*Xo));
cout.precision(5);
cout<<"a = ((V*V-Vo*Vo)/(2*X-2*Xo));"<<endl;
cout <<" acceleration is '"<<a<<"'"<<endl;
a = (NULL);
X = (NULL);
Xo = (NULL);
V = (NULL);
Vo = (NULL);
t = (NULL);
system("pause");
system("ClS");
}
elseif ((response == "t"||"T"||"time"||"Time") && (V!=NULL) &&(Vo!= NULL) && (a!=NULL))
{
t = ((V-Vo)/a);
cout.precision(5);
cout <<"t = ((V-Vo)/a);"<<endl;
cout <<" Time is '"<<t<<"'"<<endl;
a = (NULL);
X = (NULL);
Xo = (NULL);
V = (NULL);
Vo = (NULL);
t = (NULL);
system("pause");
system("ClS");
}
elseif ((response == "t"||"T"||"time"||"Time") && (X!=NULL) &&(Xo!= NULL) && (V!=NULL)&& (Vo!=NULL))
{
t = (2*(X-Xo/(Vo+V)));
cout.precision(5);
cout <<"t = (2*(X-Xo/(Vo+V)));"<<endl;
cout <<" Time is '"<<t<<"'"<<endl;
a = (NULL);
X = (NULL);
Xo = (NULL);
V = (NULL);
Vo = (NULL);
t = (NULL);
system("pause");
system("ClS");
}