//number==0时,if语句中的return语句就会终止函数的调用以避免出现除数为0的情况
// voidReturn.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
//void函数中的return语句
//
void icecreamDivision(int custormerNumber, double icecreamTotalWeight);
int main(int argc, char* argv[])
{
int number;
double totalWeight;
cout <<"Enter the number of custormers: ";
cin >>number;
cout <<"Enter the weight of ice cream to divided: ";
cin >>totalWeight;
icecreamDivision(number, totalWeight) ;
return 0;
}
void icecreamDivision(int custormerNumber, double icecreamTotalWeight){
double portion; //**
if (custormerNumber == 0){
cout <<"Cannot divide among zero customers.\n";
return ; //如果number为0,则函数执行终止
}
portion = icecreamTotalWeight / custormerNumber ;
cout <<"Each one receives "
<< portion <<" ounces of ice cream."<<endl;
}


posted on
浙公网安备 33010602011771号