Saturday 21 September 2013

Basic Math

It was good exercise because I did not know how to use command line arguments using visual studio. Anyway, here is my code and feel free to ask question or leave comments.
#include <iostream>
using namespace std;

#define left atoi(arg[1])
#define right atoi(arg[3])
#define OPERAND arg[2]

int main(int argc, char* arg[]){
int setOperand = 0;
int res=0;

if(!strcmp(OPERAND,"+")){
setOperand=1;
}
else if(!strcmp(OPERAND,"-")){
setOperand=2;
}
else if(!strcmp(OPERAND,"*")){
setOperand=3;
}
else if(!strcmp(OPERAND,"/")){
setOperand=4;
}

switch(setOperand){
case 1:
res=left + right;
cout<<res<<endl;
break;
case 2:
res=left - right;
cout<<res<<endl;
break;
case 3:
res=left * right;
cout<<res<<endl;
break;
case 4:
res=left / right;
cout<<res<<endl;
break;

default:
cout<<"<number> <+-x/> <number>"<<endl;
}

}

Tuesday 17 September 2013

Hello everyone, and welcome to my blog.
Exercise1 was pretty straight forward and just took me a few minutes to do it. You can see my codes at my github account. If any question about Exercise1, feel free to ask.
Good Luck