So the last part seems fair for me but doesn't show any result of cal cal2 in the switch case. I tried to put switch case after the else statement I been stuck in this situation for a day and still couldn't find a solution.
int main(void){
int a;
int b;
int c;
double root;
int result;
int cal;
int cal2;
printf("Type value for a ");
scanf("%d",&a);
printf("Type value for b ");
scanf("%d",&b);
printf("Type value for c ");
scanf("%d",&c);
//Root of quadratic equation
//x=(-b(+-)sqrt(pow(b,2),-4ac))/2a
root=pow(b,2)-(4*a*c);
cal=((-b)+sqrt(root))/(2*a);
cal2=((-b)-sqrt(root))/(2*a);
if(root >=0){
printf("Type 0 for both roots or 1 for one roots ");
scanf("%d",result);
switch(result){
case 0:
printf("The calculation of quadratic equation is %d and %d",cal, cal2);
break;
case 1:
printf("One of the calculation of quadratic equation is %d",cal);
break;
default:
printf("Hard\n");
break;
}
else{
printf("Error");
}
}
Aucun commentaire:
Enregistrer un commentaire