[英]C program working half when you run it from cmd file
I was coding a C program that gives us the area of sphere and circle.我正在编写一个 C 程序,它为我们提供了球体和圆的面积。 You put inputs and than it calculates.您输入输入,然后计算。 But there is a problem.但有一个问题。 I have done this project for pi day and I must send it to someone.我已经为 pi day 完成了这个项目,我必须将它发送给某人。 When I open the program from exe file it can only go for circle and spehere's radius input part.当我从 exe 文件打开程序时,它只能 go 用于圆和球体的半径输入部分。 When you input something, it closes itself.当您输入某些内容时,它会自行关闭。 When I run it from Dev C++ there isn't any problem.当我从 Dev C++ 运行它时,没有任何问题。 What is wrong with exe file? exe文件有什么问题?
#include <stdio.h>
#include <conio.h>
#define PI 3.14159265
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
getch();
char bilgi;
printf("Kurenin hacmini mi yoksa dairenin alanini mi hesaplamak istersiniz?\n");
printf("Daire icin girdi kismina d, kure icin k yaziniz:");
scanf("%c", &bilgi);
if(bilgi == 'k') {
float yaricap;
float hacim;
printf("Merhaba, bu fonksiyon kure hacmini hesaplamak icin tasarlanmistir.\n");
printf("Lutfen kurenin yaricapini giriniz:");
scanf("%f", &yaricap);
hacim = (4.00*3.00)*PI*(yaricap*yaricap*yaricap);
printf("Kurenin hacmi %f", hacim);
return 0;
} else if(bilgi == 'd'){
getch();
float yaricapdaire;
float alan;
printf("Bu fonksiyon dairenin alanini hesaplamak icin tasarlanmistir.\n");
printf("Lutfen dairenin yaricapini giriniz:");
scanf("%f", &yaricapdaire);
alan = PI*(yaricapdaire*yaricapdaire);
printf("Dairenin alani %f", alan);
return 0;
}
return 0;
}
I fixed it.我修好了它。 Putting a getch();
放一个getch();
before every return 0;
在每次return 0;
fixed it.解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.