我一直試圖解決這個錯誤半個小時了。 如何獲得此代碼的工作?如何解決錯誤:其他沒有以前如果
以下是輸入,請指出我的錯誤。
#include <stdio.h>
#include <math.h>
void main()
{
const float pi = 3.142;
int choice;
float radius, volume, volts, ohms, watts, mass, accel, force;
printf("\n1. Calculate the volume of a sphere");
printf("\n2. Calculate the power of a circuit");
printf("\n3. Calculate the force of an object");
printf("\n-----------------------------------\n");
printf("What is your choice? : ");
scanf("%d", &choice);
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...");
getch();
}
C++ **或* * C?看起來更像C,壽。 – Downvoter
在您的代碼中正確放置大括號('{}'),以解決錯誤。 –
@cad:看起來更像Python(但仍然格式不正確)。也許OP認爲每種編程語言都使用縮進作爲語法元素? – Olaf