need help with a kinematics calculator. if & else statements

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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

#include <iostream>

using namespace 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");
        }
    else if ((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");
        }
    else if ((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");
        }

    else if ((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");
        }
    else if ((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");
        }
Last edited on
This is wrong
if (response == "a"||"A" ... )

Should look like
if (response == "a"|| response == "A" ... )

The first way tries to evaluate "A" , which could turn out to be true since it's non-zero, instead of comparing response to "A"
holy cow i feel really dumb thanks!
Registered users can post here. Sign in or register to post.