struct 和 printf

/*
1 500 魔力奶茶 8 10 
2 500 茉莉奶茶 8 10
3 500 磨砺奶茶 8 10
4 500 莫离奶茶 8 10
5 500 美丽奶茶 8 10
*/

/*
string 转 char 数组 c_str()
printf 函数
%s 字符串 如果报错,加上 c_str()函数转换类型
%c 字符 
%d 整形
%f 浮点型 保留小数%.2f (两位小数)
%2d 输出最低2个宽域得数字 
默认右对齐 如果需要左对齐则加一个负号 %-2d
*/ #include <iomanip> #include <iostream> using namespace std; struct nc{ char Name[100]; int ml; int id; int money; int kc; }; int main(){ nc a[10]; for(int i=0;i<5;i++){ printf("请输入奶茶第【%d】杯奶茶:\n",i+1); cin>>a[i].id>>a[i].Name>>a[i].money>>a[i].ml>>a[i].kc; printf("奶茶【%s】已经录入\n",a[i].Name); cout<<endl; } system("cls"); for(int i=0;i<5;i++){ if(i==0){ printf("编号,名称,价格,容量,库存\n"); } printf("%d,%s,%.2f,%d,%d\n",a[i].id,a[i].Name,a[i].money,a[i].ml,a[i].kc); } return 0; }

 

posted @ 2024-12-01 10:00  郭立恒  阅读(13)  评论(0)    收藏  举报