不知道问题出在哪里...fstream问题

kimi876 2009-09-23 12:41:04
不知道怎样才能把红色字部分的内容写在txt里面
刚学C++...囧
#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int height, feet, inches, weight;
double BMI;

int main() {
string height, feet, inches, weight, BMI;

ofstrem outfile;
outfile.open("HW.txt");


void promptUser(void);

outfile.setf(ios::fixed,ios::floatfield);

promptUser();


while (BMI > 0) {
if (BMI < 18.5) {
outfile << "Your MBI is " << BMI << ", "
<< "indicating your weight is in the Underweight category\n"
<< "for adults of your height" << endl << endl;

promptUser();
}

if ((BMI >= 18.5) && (BMI < 24.9)) {
outfile << "Your MBI is " << BMI << ", "
<< "indicating your weight is in the Normal category\n"
<< "for adults of your height" << endl << endl;

promptUser();
}

if ((BMI >= 25.0) && (BMI < 29.9)) {
outfile << "Your MBI is " << BMI << ", "
<< "indicating your weight is in the Overweight category\n"
<< "for adults of your height" << endl << endl;

promptUser();
}

if (BMI >= 30.0) {
outfile << "Your MBI is " << BMI << ", "
<< "indicating your weight is in the Obese category\n"
<< "for adults of your height" << endl << endl;

promptUser();
}
}
outfile.close();
system("PAUSE");
return EXIT_SUCCESS;
}


void promptUser() {

cout << "Enter the patient's height"
<< "(in ft and inches-Enter 0 0 to stop): ";
cin >> feet >> inches;
cout << "Enter the patient's weight(in pounds): " ;
cin >> weight;

height = 12 * feet + inches;
cout.precision(1);
BMI = weight * 703 / ( height * height );

outfile << "Height: " << feet << " feet, "
<< inches << " inches" << endl;
outfile << "Weight: " << weight << " pounds" << endl;


}
...全文
153 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jkx01whg 2009-09-24
  • 打赏
  • 举报
回复
void promptUser( ofstream& );
........

void promptUser( ofstream & outfile )
{
.......
}


还有ofstrem outfile; 应为ofstream outfile;
oyster2008 2009-09-24
  • 打赏
  • 举报
回复
string height, feet, inches, weight, BMI
上面这个BMI是干什么的?与全局变量同名了,删了应该就可以了。
kimi876 2009-09-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ysuliu 的回复:]
补充:

这样使用: promptUser(outfile);


引用 1 楼 supermegaboy 的回复:
promptUser改为这样:


void promptUser( ofstream& );
........

void promptUser( ofstream & outfile )
{
  .......
}


还有ofstrem outfile; 应为ofstream outfile; 少了个a

[/Quote]
還是不行啊...while裏面的BMI寫不到....
zgjxwl 2009-09-24
  • 打赏
  • 举报
回复
up
kimi876 2009-09-24
  • 打赏
  • 举报
回复
行了....
小弟萬分感謝了
飞天御剑流 2009-09-23
  • 打赏
  • 举报
回复
promptUser改为这样:


void promptUser( ofstream& );
........

void promptUser( ofstream & outfile )
{
.......
}


还有ofstrem outfile; 应为ofstream outfile; 少了个a
ysuliu 2009-09-23
  • 打赏
  • 举报
回复
补充:

这样使用: promptUser(outfile);


[Quote=引用 1 楼 supermegaboy 的回复:]
promptUser改为这样:


void promptUser( ofstream& );
........

void promptUser( ofstream & outfile )
{
  .......
}


还有ofstrem outfile; 应为ofstream outfile; 少了个a
[/Quote]

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧