import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *vegetable=@[@{@"name":@"芹菜",@"count":@"2",@"price":@"2.5"},@{@"name":@"口蘑",@"count":@"1.7",@"price":@"6"},@{@"name":@"红薯",@"count":@"3.2",@"price":@"1.5"}
];
double shishou=50;
NSString * name=@"";
double count=0;
double price=0;
double s=0;
double s1=0;
double sum=0;
NSLog(@"名称 单价 数量 价格");
for (NSDictionary *d in vegetable) {
s=[d[@"count"]doubleValue]*[d[@"price"]doubleValue];
name=d[@"name"];
count=[d[@"count"]doubleValue];
price=[d[@"price"]doubleValue];
s1=s1+s;
sum=50-s1;
NSLog(@"%@ %.1lf %.1lf %.1lf",name,count,price,s);
}
NSLog(@"实收:%.1lf 应收:%.1lf 找零:%.1lf",shishou,s1,sum);
}
return 0;
}
网友评论