-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandard_Calculator-001.c
48 lines (48 loc) · 1.28 KB
/
Standard_Calculator-001.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
int main()
{
int Expression[50];
printf("Enter : ");
gets(Expression);
for(int i = 0;i < 50;++i)
{
switch (Expression[i])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
case '^':
case '/':
case '*':
if(i == 0)
{
printf("Variable must be before these expressions");
}
if(Expression[i+1] == '^' || Expression[i+1] == '/' || Expression[i+1] == '*')
{
printf("These expressions cannot be placed one after the other.");
}
break;
case '+':
case '-':
if(Expression[i+1] == '^' || Expression[i+1] == '/' || Expression[i+1] == '*')
{ printf("These expressions cannot be placed one after the other.");
}else if(Expression[i+1] == '+' || Expression[i+1] == '-')
{ if(Expression[i+2] == '+' || Expression[i+2] == '-')
{printf("These expressions cannot be placed one after the other.");}
}
break;
default:
break;
}
}
return 0;
}