As my first real test I wanted to build a better expr.
But it doesn't seem to do any adding or print the answer.
Here is the code:
Code: Select all
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[])
{
int proarg;
float fltAnswer;
if ( argc != 4 )
cout << "Usage: expr number1 +-/* number2";
else
float arg1 = atof(argv[2]);
float arg2 = atof(argv[4]);
if (argv[3] == "/")
proarg = 1;
else if (argv[3] == "*")
proarg = 2;
else if (argv[3] == "+")
proarg = 3;
else if (argv[3] == "-")
proarg = 4;
switch (proarg)
{
case 1 :
fltAnswer = (float) arg1 / arg2;
cout << fltAnswer;
break;
case 2 :
fltAnswer = (float) arg1 * arg1;
cout << fltAnswer;
break;
case 3 :
fltAnswer = (float) arg1 + arg2;
cout << fltAnswer;
break;
case 4 :
fltAnswer = (float) arg1 - arg1;
cout << arg1 << "+" << arg2 << fltAnswer;
break;
}
}
Help anyone?