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(@"名稱 單價(jià) 數(shù)量 價(jià)格");
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(@"實(shí)收:%.1lf 應(yīng)收:%.1lf 找零:%.1lf",shishou,s1,sum);
}
return 0;
}