So this is my BasicMath solution, a bit late but still in
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
int isNum(int length, char* h){
int result;
int i;
int x;
for(i=0;i<length;i++){
result = isnan(h[i]);
if(result==0){x++;}
}
if(x>0){return 1;}
else{return 0;}
}
int main(int argc, char* argv[]){
int length;
int i;
int x;
int y;
int lengthOne;
int lengthTwo;
char* hOne;
char* hTwo;
int isNumOne;
int isNumTwo;
lengthOne = strlen(argv[1]);
lengthTwo = strlen(argv[3]);
hOne = argv[1];
hTwo = argv[3];
isNumOne = isNum(lengthOne, hOne);
isNumTwo = isNum(lengthTwo, hTwo);
if(isNumOne==1 && isNumTwo==1){
x = atoi(hOne);
y = atoi(hTwo);
if(*argv[2]=='+'){cout<<x + y<<endl;}
else if(*argv[2]=='-'){cout<<x-y<<endl;}
else if(*argv[2]=='x'){cout<<x*y<<endl;}
else if(*argv[2]=='/'){cout<<x/y<<endl;}
}
else{cout<<"<number> <+-x/> <number><ENTER>"<<endl;}
return 0;
}
No comments:
Post a Comment