编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习6

#include <iostream>
using namespace std;
struct CandyBar
{
 char kind[20];
 float weight;
 int calory;
};
void Display(CandyBar ca,int n)
{
    cout<<"The kind of ca["<<n<<"] is: "<<ca.kind<<endl;
 cout<<"The weight of ca["<<n<<"] is: "<<ca.weight<<endl;
 cout<<"The calory of ca["<<n<<"] is: "<<ca.calory<<endl;
}
int main()
{
  //声明,初始化
 CandyBar ca[3]=
 {
  {"Cindy Tian", 0.5, 366},
  {"Pax Congo", 70, 500},
  {"Young Yang", 54, 200}
 };
 Display(ca[0],1);
 Display(ca[1],2);
 Display(ca[2],3);
 system("pause");
 return 0;
}