Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What's wrong with this code ?

+2 votes
asked Jun 7, 2020 by Sandile Mkhize (140 points)
#include <stdio.h>
 

int main()
{
    int dia,Dia;
    float pi=3.14,area;
    
    printf("enter inner diameter of a washer in centimeter : ");
    scanf("%d",& dia);
    printf("enter outer diameter of a washer in centimeter:");
    scanf ("%d",& Dia);
    
    area =pi* ((1/4)*(Dia)^2-(1/4)*(dia)^2);
    
    
    if (dia > Dia){
        printf ("check your  measurements !!!");
    
    }else{
        printf ("the Area of a washer is %f squarecentimeters" ,area);
    }
    

    return 0;
}

8 Answers

+1 vote
answered Jun 8, 2020 by AbhishekKumarGhosh (160 points)
For putting power, one must use the pow function defined under #include<math.h>
0 votes
answered Jun 8, 2020 by FahadRizvi (140 points)
You don't use ^ in c language. Instead you should call library (math.h) and try using pow() function. It'll work
0 votes
answered Jun 8, 2020 by peppo65 (140 points)
1/4 between brackets will likely evaluate to 0. Try (pi*Dia*Dia)/4.0 instead.

Furthermore, the check for Dia > dia could be moved at the beginning, so to avoid computing area in case dia > Dia.
+1 vote
answered Jun 8, 2020 by LiOS (6,420 points)
In C, you don't use ^ to represent a power. Instead, within the math.h system header file, there is a pow() function.

pow(x, y) where x is raised by y, which are passed in as double data types.
0 votes
answered Jun 14, 2020 by karibasava TG (140 points)

their instead of multiplying 1/4 each time you can take common and multiply once.

0 votes
answered Jun 25, 2020 by SEENIVASAN (140 points)
^ its an bit wise operator.In c we can take the power the number using pow(x,y) which is in the #include<math.h>

1.use #include<math.h>

2.replace ^ ----> pow(x,y)

here x is the base value. y is the power value
0 votes
answered Jun 26, 2020 by Vinay Dangayach (140 points)
#include <stdio.h>
#include<math.h>

int main()
{
    int d,D;
    float pi=3.14,area,k;
    
    printf("enter inner diameter of a washer in centimeter : ");
    scanf("%d",& d);
    printf("enter outer diameter of a washer in centimeter:");
    scanf ("%d",& D);
    printf("D and d are %d and %d respectively ",D,d);
     k=(pow(D,2)-pow(d,2));
     area=pi*k/4;
    
    
    if (d > D){
        printf ("check your  measurements !!!");
    
    }else{
        printf ("the Area of a washer is %f squarecentimeters" ,area);
    }
    

    return 0;
}

try this

hope it helps
0 votes
answered Jul 6, 2020 by umesh bhukya (140 points)
CHECK THIS OUT

#include <stdio.h>
 

int main()
{
    int dia,Dia;
    float area;
    
    printf("enter inner diameter of a washer in centimeter : ");
    scanf("%d",& dia);
    printf("enter outer diameter of a washer in centimeter:");
    scanf ("%d",& Dia);
    
    area =0.785*((Dia)*(Dia)-(dia)*(dia));
    
    
    if (dia > Dia){
    printf ("check your  measurements !!!");
    
    }else{
     printf ("the Area of a washer is %f squarecentimeters" ,area);
    }
    

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...