[C/OC的那点事儿]字符串的使用:根据出生年份计算星座

//
//  main.m
//  根据出生日期计算星座
//
//  Created by lichan on 13-11-28.
//  Copyright (c) 2013年 com.lichan. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
     
        
        
        char birthday[20];
        printf("请输入你的出生日期(阳历)(格式:yyyymmdd):");
        scanf("%s",birthday);
        NSString *ymd  = [[NSString alloc]initWithUTF8String:birthday];
       // NSString *md = [ymd substringFromIndex:4];
        NSRange monthRange ;
        monthRange.length = 2;
        monthRange.location = 4;
        NSString *month = [ymd substringWithRange:monthRange];

        
        int intMonth = [month intValue];
       // NSLog(@"%d",[month intValue]);
        //--------------------
        NSRange dayRange ;
        dayRange.length = 2;
        dayRange.location = 6;
        NSString *day = [ymd substringWithRange:dayRange];
        
        int intDay = [day intValue];
       // NSLog(@"day:%@",day);
        
        switch (intMonth) {
            case 1:
            {
                if (intDay <= 19)
                    NSLog(@"你是 魔蝎座.");
                else
                    NSLog(@"你是 水瓶座.");
               break;
            }
            case 2:
            {
                if (intDay <= 18)
                    NSLog(@"你是 水瓶座.");
                else
                    NSLog(@"你是 双鱼座.");
                break;
            }
            case 3:
            {
                if (intDay <= 20)
                    NSLog(@"你是 双鱼座.");
                else
                    NSLog(@"你是 白羊座.");
                break;
            }
            case 4:
            {
                if (intDay <= 19)
                    NSLog(@"你是 白羊座.");
                else
                    NSLog(@"你是 金牛座.");
                break;
            }
            case 5:
            {
                if (intDay <= 20)
                    NSLog(@"你是 金牛座.");
                else
                    NSLog(@"你是 双子座.");
                break;
            }
            case 6:
            {
                if (intDay <= 21)
                    NSLog(@"你是 双子座.");
                else
                    NSLog(@"你是 巨蟹座.");
                break;
            }
            case 7:
            {
                if (intDay <= 22)
                    NSLog(@"你是 巨蟹座.");
                else
                    NSLog(@"你是 狮子座.");
                break;
            }
            case 8:
            {
                if (intDay <= 22)
                    NSLog(@"你是 狮子座.");
                else
                    NSLog(@"你是 处女座.");
                break;
            }
            case 9:
            {
                if (intDay <= 22)
                    NSLog(@"你是 处女座.");
                else
                    NSLog(@"你是 天秤座.");
                break;
            }
            case 10:
            {
                if (intDay <= 23)
                    NSLog(@"你是 天秤座.");
                else
                    NSLog(@"你是 天蝎座.");
                break;
            }
            case 11:
            {
                if (intDay <= 22)
                    NSLog(@"你是 天蝎座.");
                else
                    NSLog(@"你是 射手座.");
                break;
            }
            case 12:
            {
                if (intDay <= 19)
                    NSLog(@"你是 魔蝎座.");
                else
                    NSLog(@"你是 水瓶座.");
                break;
            }
     
            default:
                break;
        }
        
        
        
        
        // insert code here...
        
    }
    return 0;
}

//touchdb@sina.com lllm126

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值