ده برنامج آلة حاسبة بلغة الـ C
أردت وضع زر فيها يتم إستخدامه على مثال زر AC في الالة الحاسبة العادية إذا حدثت مشكلة أو شرط أدى لحدوث Hung للبرنامج نضغط عليه يجعل قيم المتغيرات كلها صفر و يعيد البرنامج للوضع الأول و يطلب الرقم الأول
و إذا أدخل حرف بدلاً من رقم أو بدلاً من ادخال عملية رباضية ضمن العمليات التي يقوم بها البرنامج تخرج له رسالة تقول لا أفهم ما أردت أدخل عملية صحيحة
ده البرنامج
و لا أدري أين المشكلة
// Calculator
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main ()
{
double a1,c1;
char oper;
float a,b,c;
int counter;
printf ("Enter Your Numbers and Operation \n To Exit press E \n Write A to Start again\n");
counter = 1;
while ((oper!='e')||(oper!='E'))
{
fflush( stdin );
if (counter==1)
scanf("%f %c",&a,&oper);
else
{
// do
scanf ("%c",&oper);
// while(oper == '\n');
}
if ((oper == '+')||(oper == '-')||(oper == '*')||(oper == '/')||(oper == '%')||( oper == '^'))
scanf ("%f",&b);
if (oper == '+')
{
c = a + b;
printf ("%f\n",c);
}
else if (oper == '-')
{
c = a - b;
printf ("%f\n",c);
}
else if (oper == '*')
{
c = a * b;
printf ("%f\n",c);
}
else if (oper == '/')
{
if (b==0)
printf (" Error, You cant divid on Zero\n");
else
{
c = a / b;
printf ("%f\n",c);
}
}
else if (oper == '%')
{
c = fmod (a,b);
printf ("%f\n",c);
}
else if (oper == '^')
{
c = pow (a,b);
printf ("%f\n",c);
}
else if (oper == 's')
{
c = sin (a);
printf ("%f\n",c);
}
else if (oper == 'o')
{
c = cos (a);
printf ("%f\n",c);
}
else if (oper == 't')
{
a1=a;
c1 = tan(a1);
printf ("%lf\n",c1);
c=c1;
}
else if (oper == 'l')
{
if (a<0)
printf ("Error, U can't take log for negative\n");
else
{
c = log10(a);
printf ("%f\n",c);
}
}
else if (oper == 'n')
{
if (a<0)
printf ("Error, U can't take lin for negative\n");
else
{
c = log (a);
printf ("%f\n",c);
}
}
else if (oper == 'q')
{
if (a > 0)
{
c = sqrt (a);
printf ("%f\n",c);
}
else
printf ("Error, You cant Evaluate the squareroot for Negative number or Zero\n");
}
else if (oper == 'tan')
{
c = atan(a);
printf ("%f\n",c);
}
else if ((oper == 'e')||(oper == 'E'))
exit (EXIT_SUCCESS);
else if ((a == 'A')||(oper == 'A')||(b == 'A'))
{
a = 0;
b = 0;
c = 0;
a1 = 0;
c1 = 0;
printf ("Start Again\n");
if ("counter == 1")
continue;
else
scanf ("%f",&a);
continue;
}
else
{
if (counter == 1)
{
printf ("I can't Understand that\n Enter right operation\n");
continue;
}
else
printf ("I can't Understand that\n Enter right operation\n");
}
counter = counter +1;
a=c;
}
return 0;
}