so basically my if and else statement isn't working for me. when i try to put in "us" when it ask for my unit system, it'll skip to "press any key to continue" and i pretty much don't know what im messing up on.
// This program is to approximate a vehicle's speed before it gets into an accident.
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
// ***************************** variables
char answer;
double vf;
double c;
double ds;
double f;
double vi;
double vi2;
double v;
#define c1 12.96
#define g1 9.81
#define c2 .4649
#define g2 32.2
// ******************** commands
cout << "is the unit system in metric or U.S. customary units? \ntype in M for metric or US for U.S. customary units: ";
cin >> answer;
if (answer == 'm' || answer == 'M')
{
cout << "Type in the estimated speed at impact:";
cin>> vf;
cout << "Type in the skid mark distance:";
cin>> ds;
cout << "Type in the road's coefficient of friction:";
cin>> f;
// ******************* formulas
v = (vf*vf);
vi = sqrt(v+2*c1*ds*g1*f);
vi2 = sqrt(v+2*c2*ds*g2*f);
cout << setprecision(2) << fixed;
cout << "The traveling speed of the car is: "<< vi << " km/hr" << endl;
}
// ********************** us metric system output
else if(answer == 'us' || answer =='US')
{
cout << "Type in the estimated speed at impact:";
cin>> vf;
cout << "Type in the skid mark distance:";
cin>> ds;
cout << "Type in the road's coefficient of friction:";
cin>> f;
cout << setprecision(2) << fixed;
cout << "The traveling speeed of the car is: "<< vi2 << " mi/hr" << endl;
}
system("pause");
return 0;
}
Without looking too closely (there may be more problems), answer is a char, which can hold one character. Change it to a std::string and change all your string constants to use "double quotes", not 'single' (single are for single-character constants).