/***************************************************
F = m a Program

Write a program that solves for the unknown variable
in the F = m a equation.  The user enters two
variable = value pairs (e.g "m = 10.0 F = 3.5") and
the program writes the unknown variable and its
value ("a = .35" in our example).

In this solution, we first sort our variables so
that var1 is always before var2 in alphabetical
order, and this makes it easier to figure out which
variable we're solving for.
***************************************************/
#include <iostream>
using namespace std;

int main()
{

  cout << "The F = m a Program" << endl;

  // Read first variable/value pair
  char var1,c;
  double val1;
  cout << "Enter <var> = <value> : ";
  cin >> var1 >> c >> val1;

  // Read second variable/value pair
  char var2;
  double val2;
  cout << "Enter <var> = <value> : ";
  cin >> var2 >> c >> val2;

  // ensure that var1 is alphabetically before var2
  if (var1 > var2)
  {
    // swap var1 and var2
    char tvar;
    tvar = var1;
    var1 = var2;
    var2 = tvar;

    // swap val1 and val2
    double tval;
    tval = val1;
    val1 = val2;
    val2 = tval;
  }

  // Decide which variable is missing & solve
  if (var1 == 'F' && var2 == 'a')
    cout << "m = " << val1 / val2 << endl;
  if (var1 == 'F' && var2 == 'm')
    cout << "a = " << val1 / val2 << endl;
  if (var1 == 'a' && var2 == 'm')
    cout << "F = " << val1 * val2 << endl;

 return 0;
}