Aug 19, 2015 at 4:15pm UTC
The static cast was doing what it was supposed to. And reality check I commented the static cast out and the program works the same. Shouldn't the program throw error? I also plan on ridding the code of magic numbers.
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
#include<iostream>
using namespace std;
int main ()
{
double number_1; double number_2;
cout<<"input 2 numbers for math ops" <<endl;
cout<<"Number 1 :" ;
cin>>number_1;
cout<<"Number 2 :" ;
cin>>number_2;
cout<<endl;
char x;
cout<<"input an operator (+,-,*,/) :" ;
cin>>x;
cout<<"------------" <<endl;
double result(0); int flag(0);int y(0);
//y = static_cast<int>(x); //<<endl;
if (x == 42){cout<<number_1 * number_2; ++flag;}; //<<f;};
if (x == 43){cout<<number_1 + number_2; ++flag;};
if (x == 45){cout<<number_1 - number_2; ++flag;};
if (x == 47){cout<<number_1 / number_2; ++flag;};
if (!flag) cout<<"must put in +/*- operator" <<endl;
return 0;
}
Last edited on Aug 19, 2015 at 4:15pm UTC