在VC6.0软件里面开启我编写的这个小程序,可以完整运行。从文件夹里直接运行exe程序,最后一步就直接闪退了。
这是源代码
#include<stdio.h>
main()
{
float a,b,c,d;
printf("请输入身高(米)\n");
scanf("%f",&a);
printf("请输入体重(公斤)\n");
scanf("%f",&b);
d=a*a;
c=b/d;
printf("你的健康指数是%f(小于18.5属于偏瘦。介于18.5和20.9之间,属于苗条。介于20.9和24.9之间属于适中。超过24.9偏胖。)\n",c);
if(c>24.9)
printf("\n太胖了,你要减肥了\n");
if(20.9>c>24.9)
printf("\n体重健康,注意保持\n");
if(18.5>c>20.9)
printf("\n体重健康,比较苗条,注意保持\n");
if(c<18.5)
printf("\n瘦成骨头啦,增点重。\n");
return 0;
}
return 0;前面添加 system("pause");或者getchar();
要不试试再main前加一个int之类的?
#include<iostream>
using namespace std;
int main() {
float a, b, c, d;
cout << "请输入身高(米)" << endl;
cin >> a;
cout << "请输入体重(公斤)" << endl;
cin >> b;
d = a * a;
c = b / d;
cout << "你的健康指数是" << c << "小于18.5属于偏瘦。介于18.5和20.9之间,属于苗条。介于20.9和24.9之间属于适中。超过24.9偏胖." << endl;
if (c > 24.9)
cout << "太胖了,你要减肥了" << endl;
if (20.9 > c > 24.9)
cout << "体重健康,注意保持" << endl;
if (18.5 > c > 20.9)
cout << "体重健康,比较苗条,注意保持" << endl;
if (c < 18.5)
cout << "瘦成骨头啦,增点重." << endl;
system("pause");
return 0;
}
加个延时函数也可以,不然exe文件运行完直接关闭了
c++行么?
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
float a, b, c, d;
cout << "请输入身高(米)" << endl;
cin >> a;
cout << "请输入体重(公斤)" << endl;
cin >> b;
d = a * a;
c = b / d;
cout << "你的健康指数是" << c << "小于18.5属于偏瘦。介于18.5和20.9之间,属于苗条。介于20.9和24.9之间属于适中。超过24.9偏胖." << endl;
if (c > 24.9)
cout << "太胖了,你要减肥了" << endl;
if (20.9 > c > 24.9)
cout << "体重健康,注意保持" << endl;
if (18.5 > c > 20.9)
cout << "体重健康,比较苗条,注意保持" << endl;
if (c < 18.5)
cout << "瘦成骨头啦,增点重." << endl;
getch();
return 0;
}