page148

// page148.cpp : 定义控制台应用程序的入口点。
//C++面向对象程序设计

//计算绿秃鹰产卵总数
//由保护区的所有动物保护着统计

#include "stdafx.h"
#include <iostream>
using namespace std ;

int get_one_total();
//前条件:用户输入一系列鸡蛋数量
//最后以一个负数结束
//后条件:总数等于所有鸡蛋计数的总和

int main()
{
  cout << " This program tallies conservationst reports\n"
   << " on the green-necked vulture .\n"
   << " Each conservationist`s report consists of \n"
   << " a list of numbers . Each number is the count of \n"
   << " the eggs observed in one "
   << " green-necked vulture nest .\n"
   << " this program then tallies"
   << " the total number of eggs .\n";

  int number_of_reports;
  cout << " How many conservationist reports are there? ";
  cin >> number_of_reports;

  int grand_total = 0 , subtotal , count ;
  for (count = 1; count <= number_of_reports ; count++)
  {
   cout << endl << " Enter the report of "
    << " conservationist number "<< count << endl;
   subtotal = get_one_total();
   cout << " Total egg count for conservationist "
    << " number " << count << " is "
    << subtotal << endl ;
   grand_total = grand_total + subtotal ;
  }

  cout << endl <<" Total egg count for all reports ="
   << grand_total << endl ;

  cin >> number_of_reports;
  return 0 ;
}

 //使用iostream
 int get_one_total()
 {
  int total ;
  cout << " Enter the number of eggs in each nest .\n"
   << " Place a negative integer"
   << " at the end of your list.\n ";

  total = 0 ;
  int next ;
  cin >> next ;
  while ( next >= 0 )
  {
   total = total + next ;
   cin >> next ;
  }
 
  return total ;
 }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值