编程练习5的链接:
https://blog.csdn.net/qq_34847850/article/details/119509236?spm=1001.2014.3001.5501
根据上面内容做题:
//4.11.6.cpp -- 结构体和数组
# include <iostream>
using namespace std;
struct CandyBar
{
char kind[80];
float weight;
int calorie;
};
int main()
{
CandyBar snack[3]={{"Mocha Munch1",2.3,350},{"Mocha Munch2",3.5,300},{"Mocha Munch3",4.7,450}};
cout<<"糖块的品牌1: "<<snack[0].kind<<"\n";
cout<<"糖块的重量1: "<<snack[0].weight<<"\n";
cout<<"糖块的卡路里1: "<<snack[0].calorie<<"\n";
cout<<"糖块的品牌2: "<<snack[1].kind<<"\n";
cout<<"糖块的重量2: "<<snack[1].weight<<"\n";
cout<<"糖块的卡路里2: "<<snack[1].calorie<<"\n";
cout<<"糖块的品牌3: "<<snack[2].kind<<"\n";
cout<<"糖块的重量3: "<<snack[2].weight<<"\n";
cout<<"糖块的卡路里3: "<<snack[2].calorie<<"\n";
return 0;
}
/*
输出结果:
糖块的品牌1: Mocha Munch1
糖块的重量1: 2.3
糖块的卡路里1: 350
糖块的品牌2: Mocha Munch2
糖块的重量2: 3.5
糖块的卡路里2: 300
糖块的品牌3: Mocha Munch3
糖块的重量3: 4.7
糖块的卡路里3: 450
Press any key to continue
*/