美文网首页
字典数组结合

字典数组结合

作者: Grt婷 | 来源:发表于2017-05-15 07:25 被阅读0次

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;

}

相关文章

网友评论

      本文标题:字典数组结合

      本文链接:https://www.haomeiwen.com/subject/bswsvttx.html