Help with switch statement

Hello I am having trouble with my C++ homework as I do not fully understand how to use a switch statement on this problem or at all. The question goes like this:

SSD = c(vt + cv^2/2g(f+G))

SSD is the stopping sight distance (m or ft)
c is the conversion factor = .278 m-hr/km-s (metric units) or 1.47 ft-hr/mi-sec (U.S. customary units)
v is the speed (km/hr or mi/hr)
t is the reaction time (sec)
g is the acceleration caused by gravity = 9.81 m/s^2 or 32.2 ft/sec^2
f is the road's coefficient of friction (dimensionless)
G is the road grade, as a decimal (dimensionless)

Using this equation, write, compile and run a C++ program that first prompts the user for the unit system to use (metric or U.S. customary units). Based on the response, your program should select the correct conversion factor, request the remaining data, and display stopping sight distance.

Can anyone help me with this? It would be much appreciated.

I don't see anything in the problem statement that says anything about a switch statement.

You could do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
  char sys;
 
  cout << "Select Metric or English (m/e): "
  cin >> sys;
  switch (sys)
  {
  case 'e':  //  Do English calculations
                 break;
  case 'm': // Do metric calculations
                break;
  default:  cout << "Selection not recognized" << endl;
  }

Last edited on
The instructor wants us to use a switch statement when she briefly went over it and now I'm confused on how to use it.
Last edited on
This is what I have so far but I do not know how to assign the conversions and I'm getting warnings.

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
 #include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double SSD, c, v, t, g, f, G;
    char sys;
    SSD = c * (v * t + (c * v *v)/(2 * g * (f + G)));

    cout << "Please enter the unit system to use, Metric or English units (select m or e): ";
    cin >> sys;

    switch (sys)
    {
case 'e':  //  Do English calculations 
    break;
case 'm':  //  Do Metric calculations 
    break;
    default: cout << "Selection not recognized" << endl;

    }

    cout << "Now enter speed: ";
    cin >> v;
    cout << "Now enter reaction time: ";
    cin >> t;
    cout << "Now enter the road's coefficient of friction: ";
    cin >> f;
    cout << "Now enter the road grade as a decimal: ";
    cin >> G;
    cout << "The stopping sight distance is " << SSD << endl;




    return 0;
}
Topic archived. No new replies allowed.