هذي محاولتي بهالبرنامج أبغى أعرف ايش الغلط عندي لو سمحتوا
هذا السؤال
1. Write a program that reads a string composed of two integers with a binary operation between them (+, - * or /). Your program should call a function to separate the numbers and the operation and then call a second number to calculate the result. The result should be printed in main.
وهذا هو حلي له
#include<stdio.h>
#define len 5
int func1(char );
int result(int,char,int);
int main ()
{
char string[len],num[len];
int i ,x;
printf("please enter two numbers and operation between them with space to calculate the result\n");
gets(string);
x=func1( string);
printf(" The result is %d\n",x);
return 0;
}
int func1(char string[]){
int i,m,a1,a2=0,operation;
char num[len];
while(!isspace(string)){
for(i=0;i<=len;i++);
if(isdigit(string)){
num=string;
a1= atoi(num);
break;}
switch(string){
case'+':
operation='+';
break;
case'-':
operation='-';
break;
case'*':
operation='*';
break;
case'/':
operation='/';
break;
}
if(isdigit(string)){
num=string;
a2=atoi(num);
}
i++;
}
m =result( a1, operation , a2);
return m;
}
int result(int a1,char operation ,int a2){
int resulte;
switch(operation){
case'+':
resulte=a1+a2;
break;
case'-':
resulte=a1-a2;
break;
case'*':
resulte=a1*a2;
break;
case'/':
resulte=a1/a2;
break;}
return resulte;
}طبعا الحل بلغة السي
أبي أعرف كيف اعدل الاغلاط
