Sunday 3 February 2013


TEST4U:

/*
* File: TEST4U.cpp
* Author: Akhilesh
*
* Created on February 20, 2012, 06:31 PM
*/


#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>
#include<dos.h>

/**
* author Akhilesh Dhar Dubey
**/

int main(int argc, char** argv) {
int operand1, operand2, i, j, count, calc, flag, ans, more_opr, operandCount, operandFlag;
char x[20], opr, y[10], z[10];
do {
operand1 = 0;
operand2 = 0;
i = 0;
j = 0;
count = 0;
calc = 0;
flag = 1;
ans = 0;
// more_opr=0;
operandCount = 0;
operandFlag = 1;
opr = ' ';
*x = ' ';
*y = ' ';
*z = ' ';
fflush(stdin);
// clrscr();
printf("Enter Mathematical Equation:\n");
scanf("%[^\n]s", &x);
fflush(stdin);
printf("\nprocess:");

for (i = 0; x[i] != '\0';) {

for (j = 0; x[i] == '0' || x[i] == '1' || x[i] == '2' || x[i] == '3' || x[i] == '4' || x[i] == '5' || x[i] == '6' || x[i] == '7' || x[i] == '8' || x[i] == '9'; i++, j++) {
strcpy((y + j), (x + i)); //y[j]=x[i];
}
// strcpy(y,x); //we can write this also bcoz x contain value before any opr accur.
//printf("\t\t\t %d \t\t\t\n",atoi(y));
operand1 = atoi(y);

// delay(50);

if (operandFlag) {
printf("\n%d", operand1);
operandFlag = 0;
}

if (x[i] == '+') {
opr = x[i];
i++;
more_opr++;
} else if (x[i] == '-') {
opr = x[i];
i++;
more_opr++;
} else if (x[i] == '*') {
opr = x[i];
i++;
more_opr++;
} else if (x[i] == '/') {
opr = x[i];
i++;
more_opr++;
}

/* if(more_opr >=2){
printf("wrong operation performed...");
break;
}
*/
for (j = 0; x[i] == '0' || x[i] == '1' || x[i] == '2' || x[i] == '3' || x[i] == '4' || x[i] == '5' || x[i] == '6' || x[i] == '7' || x[i] == '8' || x[i] == '9'; i++, j++) {
strcpy((z + j), (x + i));
}
//printf("\t\t\t %d \t\t\t\n",atoi(z));
operand2 = atoi(z);

// delay(50);

if (opr == '+') {
if (flag) {
calc = operand1 + operand2;
flag = 0;
} else
calc += operand2;
printf("\t%c", opr);
} else if (opr == '-') {
if (flag) {
calc = operand1 - operand2;
flag = 0;
} else
calc -= operand2;
printf("\t%c", opr);
} else if (opr == '*') {
if (flag) {
calc = operand1*operand2;
flag = 0;
} else
calc *= operand2;
printf("\t%c", opr);
} else if (opr == '/') {
if (flag) {
calc = operand1 / operand2;
flag = 0;
} else
calc /= operand2;
printf("\t%c", opr);
}

// delay(50);

printf("\t%d", operand2);

// delay(50);

printf("\t=\t%d", calc);
printf("\n");
}

printf("\nResult:");
printf("\ncalc = %d\n", calc);

printf("\nDo you want to calculate more:(1/0)");
scanf("%d", &ans);
} while (ans == 1);
return (EXIT_SUCCESS);
}
/*
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin(){
printf("Program without main !\n");
return 0;
}
*/

No comments:

Post a Comment