请用C++写一个小程序,谢谢!

2025-01-24 08:55:11
推荐回答(2个)
回答1:

#include
#include
using namespace std;
int main()
{
ofstream outfile("1.txt",ios::out);
if(!outfile)
{
cerr<<"open error!"<exit(1);
}

double i=1,Na,Nb;
double Asum=0;
double Bsum=0;

while(i<6)
{
cout<<"第"<cin>>Na>>Nb;
while(Na<10||Na>99||Nb<10||Nb>99)
{
cout<<"输入错误,请重新输入A和B的值!(A,B是两位整数)"<cin>>Na>>Nb;
}
Asum=Asum+Na;
Bsum=Bsum+Nb;
i++;
}
double sum1=Asum/5;
cout<<"A的平均值为:"<outfile<double sum2=Bsum/5;
cout<<"B的平均值为:"<outfile<cout<<"A.B的平均值已成功保存到1.txt文件中!"<outfile.close();
return 0;
}

回答2:

应该很容易吧!