我的while
循环中存在此问题。该程序在读取华氏温度后读取退出(-999)行。一开始我没有遇到这个问题,直到我试图打印出平均值的正确答案而且我毁了一切。
以下是代码:
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
void main()
{
float fahr =0 , cent = 0, fsum = 0, csum = 0;
float favg = 0;
float cavg = 0;
int temp_cnt = 0;
ofstream fout;
fout.open("temps.dat");
fout << setw(25) << "fahrenheit" << setw(20) << "centigrade" << endl;
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(1);
while (fahr != -999)
{
cout << "Enter a fahrenheit temperature enter. -999 toquit"<< endl;
temp_cnt++;
cin >> fahr;
fsum += fahr;
csum += cent;
cent = float((5.0 / 9.0))*float((fahr - 32));
fout << setw(25) << fahr << setw(20) << cent << endl;
csum = csum + cent;
}
fout << endl;
fout << setw(15) << "Average:";
favg =float ((fsum / temp_cnt));
cavg = float ((csum / temp_cnt));
fout << setw(10) << favg << setw(20) << cavg << endl;
return ;
}
temp.dat文件中的输出:
fahrenheit centigrade
86.0 30.0
91.0 32.8
87.4 30.8
100.3 37.9
98.6 37.0
77.0 25.0
83.7 28.7
-999.0 -572.8
Average: -46.9 -16.0
答案 0 :(得分:0)
行后:
self.0
添加:
zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
希望这会有所帮助。祝你好运!