#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;
#define NUM_OF_ARGUMENTS 4
void ErrorMessages(){
cout<<"<number> <+-x/> <number><ENTER>"<<endl;
}
int main(int count, char* argv[]){
double num1,num2;
char operand;
if( argv[2] != NULL)
operand = argv[2][0];
else{
ErrorMessages();
return 0;
}
if(count==NUM_OF_ARGUMENTS){
if(sscanf(argv[1],"%lf",&num1)==1&&sscanf(argv[3],"%lf",&num2)==1){
switch (operand) {
case '+': cout << num1+num2<<endl; break;
case '-': cout << num1-num2<<endl; break;
case 'x': cout << num1*num2<<endl; break;
case '/': cout << num1/num2<<endl; break;
default: ErrorMessages(); break;
}
}
else{
ErrorMessages();
return 0;
}
}
else
ErrorMessages();
return 0;
}
No comments:
Post a Comment