[Solved] How to solve Error : else without a previous if [closed]


Use braces if a if/else block has multiple lines:

if (choice==1) {
    printf("Enter value of radius (cm) : ");
    scanf("%f", &radius);
    volume = 4/3 * pi * pow(radius,3);
    printf("Volume of a sphere is %.2f", volume);
} else if (choice==2) {
    printf("Enter value of voltage (volts) : ");
    scanf("%f", &volts);
    printf("Enter value of resistance (ohms) : ");
    scanf("%f", &ohms);
    watts = pow(volts,2) / ohms;
    printf("Power of circuit is : %.2f watts", watts);
} else if (choice==3) {
    printf("Enter mass of object (kg)                : ");
    scanf("%f", &mass);
    printf("Enter acceleration (meters per second squared) : ");
    scanf("%f", &accel);
    force = mass * accel;
    printf("The force of the object is : %.2f Neutons", force);
} else printf("You've entered an invalid choice...");

Without braces your code is interpreted like

// Standalone if block
if (choice==1) 
    printf("Enter value of radius (cm) : ");
// End of the if block
// ...
// else without previous if (syntax error)
else if (choice==2)
    printf("Enter value of voltage (volts) : "); 

solved How to solve Error : else without a previous if [closed]