C++语言开发示例:03. 数据输入
cinfish.cpp
#include <iostream>
const int Max = 5;
int main()
{
using namespace std;
double fish[Max];
cout << "Please enter the weights of your fish.\n";
cout << "You may enter up to " << Max
<< " fish <q to terminate>.\n";
cout << "fish #1: ";
int i = 0;
while (i < Max && cin >> fish[i])
{
if (++i < Max)
cout << "fish #" << i + 1 << ": ";
}
double total = 0.0;
for (int j = 0; j < i; j++)
{
total += fish[j];
}
if (i == 0)
{
cout << "No fish\n";
}
else
{
cout << total / i << " = average weight of "
<< i << " fish\n";
}
cout << "Done.\n";
} 最后更新于1年前
本文由人工编写,AI优化,转载请注明原文地址: C++语言开发示例:03. 数据输入
推荐阅读
谷歌Antigravity IDE:AI智能体驱动的软件开发平台详解
7572025-11-24
Windows系统PyTorch安装教程:CUDA 12.1环境配置与TorchText版本兼容性指南
23282025-10-08
VMware Workstation 17许可证密钥及免费激活方法详解
28322025-10-26
Kaggle数据科学平台完全指南:竞赛、学习与社区全解析
2312025-11-23
Kaggle Notebook性能实测:免费GPU主机配置与运行时间分析
7842025-11-23
OpenVPN安装配置完整指南:从零搭建安全VPN服务器与客户端
18452025-10-30
评论 (0)
发表评论
昵称:加载中...
暂无评论,快来发表第一条评论吧!