佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 907|回复: 18

C Language : 请大家进来帮我debug一下 [已解决]

[复制链接]
发表于 3-10-2008 09:45 PM | 显示全部楼层 |阅读模式
  1. /*
  2. Homework for chapter 4:
  3. Write a C program that prompt the user for his or her date of birth,
  4. before determining his or her Western Zodiac Sign.
  5. The program must remain in an infinite loop
  6. (prompt the user for his or her date of birth again, after each display of the previous result)
  7. until a unique key is pressed, indicating that the user wishes to exit the program.
  8. */
  9. #include<stdio.h>
  10. void main()
  11. {
  12. int dob;
  13. do
  14. {
  15.   printf("lease enter your date of birth (in form mmdd) or 123 to exit : ";
  16.   scanf("%d",&dob);
  17.   if(dob>=0321&&dob<=0420)
  18.    printf("Your Western Zodiac Sign is Aries.\n";
  19.   else if(dob>=0421&&dob<=0520)
  20.    printf("Your Western Zodiac Sign is Taurus.\n";
  21.   else if(dob>=0521&&dob<=0620)
  22.    printf("Your Western Zodiac Sign is Gemini.\n";
  23.   else if(dob>=0621&&dob<=0720)
  24.    printf("Your Western Zodiac Sign is Cancer.\n";
  25. else if(dob>=0721&&dob<=0820)
  26.    printf("Your Western Zodiac Sign is Leo.\n";
  27.   else if(dob>=0821&&dob<=0920)
  28.    printf("Your Western Zodiac Sign is Virgo.\n";
  29.   else if(dob>=0921&&dob<=1020)
  30.    printf("Your Western Zodiac Sign is Libra.\n";
  31.   else if(dob>=1021&&dob<=1120)
  32.    printf("Your Western Zodiac Sign is Scorpio.\n";
  33.   else if(dob>=1121&&dob<=1220)
  34.    printf("Your Western Zodiac Sign is Sagittarius.\n";
  35.   else if(dob>=1221&&dob<=0120)
  36.    printf("Your Western Zodiac Sign is Capricorn.\n";
  37.   else if(dob>=0121&&dob<=0220)
  38.    printf("Your Western Zodiac Sign is Aquarius.\n";
  39.   else if(dob>=0221&&dob<=0320)
  40.    printf("Your Western Zodiac Sign is Pisces.\n";
  41. }while(dob!=123);
  42. }
复制代码
c:\documents and settings\chaiw fan\desktop\chapter 4.c(28) : error C2041: illegal digit '8' for base '8'
c:\documents and settings\chaiw fan\desktop\chapter 4.c(30) : error C2041: illegal digit '8' for base '8'
c:\documents and settings\chaiw fan\desktop\chapter 4.c(30) : error C2041: illegal digit '9' for base '8'
c:\documents and settings\chaiw fan\desktop\chapter 4.c(32) : error C2041: illegal digit '9' for base '8'

大家帮帮忙
因为我不知道它的error的意思
谢谢

[ 本帖最后由 蜡笔小烦 于 18-10-2008 03:32 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 3-10-2008 09:55 PM | 显示全部楼层
你用 08xx 會讓 compiler 以為你要用 octal value. 應該是要做 type cast 的。
我忘了怎么做 type cast. 去找找吧。
回复

使用道具 举报

发表于 3-10-2008 10:16 PM | 显示全部楼层
if(dob>=0321&&dob<=0420)
   printf("Your Western Zodiac Sign is Aries.\n");
  else if(dob>=0421&&dob<=0520)
   printf("Your Western Zodiac Sign is Taurus.\n");

把所有的"0321",“0420”前面的'0'丢掉就可以了。
我有点意见,如果我特地打我的生日是“0499“呢?
回复

使用道具 举报

 楼主| 发表于 3-10-2008 10:25 PM | 显示全部楼层
原帖由 choong218 于 3-10-2008 10:16 PM 发表
if(dob>=0321&&dob=0421&&dob


很好的问题
我现在用着switch 和 IF-ELSE一起。。。
做好再post上来。。。
回复

使用道具 举报

 楼主| 发表于 3-10-2008 10:48 PM | 显示全部楼层

  1. #include<stdio.h>
  2. void main()
  3. {
  4. int dob;
  5. int mob;
  6. char key;
  7. do
  8. {
  9.   printf("lease enter your day of birth (01-31): ";
  10.   scanf("%d",&dob);
  11.   printf("lease enter your month of birth (01-12): ";
  12.   scanf("%d",&mob);
  13.   
  14.   switch(mob)
  15.   {
  16.   case 1:
  17.    {
  18.     if(dob>=1&&dob<=20)
  19.      printf("Your Western Zodiac Sign is Capricorn.\n";
  20.     else if(dob>=21&&dob<=31)
  21.      printf("Your Western Zodiac Sign is Aquarius.\n";
  22.     else
  23.      printf("Your have entered an invalid date!\n";
  24.    }
  25.    break;
  26.   case 2:
  27.    {
  28.     if(dob>=1&&dob<=20)
  29.      printf("Your Western Zodiac Sign is Aquarius.\n";
  30.     else if(dob>=21&&dob<=29)
  31.      printf("Your Western Zodiac Sign is Pisces.\n";
  32.     else
  33.      printf("Your have entered an invalid date!\n";
  34.    }
  35.    break;
  36.   case 3:
  37.    {
  38.     if(dob>=1&&dob<=20)
  39.      printf("Your Western Zodiac Sign is Aquarius.\n";
  40.     else if(dob>=21&&dob<=31)
  41.      printf("Your Western Zodiac Sign is Pisces.\n";
  42.     else
  43.      printf("Your have entered an invalid date!\n";
  44.    }
  45.    break;
  46.   case 4:
  47.    {
  48.     if(dob>=1&&dob<=20)
  49.      printf("Your Western Zodiac Sign is Aries.\n";
  50.     else if(dob>=21&&dob<=30)
  51.      printf("Your Western Zodiac Sign is Taurus.\n";
  52.     else
  53.      printf("Your have entered an invalid date!\n";
  54.    }
  55.    break;
  56.   case 5:
  57.    {
  58.     if(dob>=1&&dob<=20)
  59.      printf("Your Western Zodiac Sign is Taurus.\n";
  60.     else if(dob>=21&&dob<=31)
  61.      printf("Your Western Zodiac Sign is Gemini.\n";
  62.     else
  63.      printf("Your have entered an invalid date!\n";
  64.    }
  65.    break;
  66.   case 6:
  67.    {
  68.     if(dob>=1&&dob<=20)
  69.      printf("Your Western Zodiac Sign is Gemini.\n";
  70.     else if(dob>=21&&dob<=30)
  71.      printf("Your Western Zodiac Sign is Cancer.\n";
  72.     else
  73.      printf("Your have entered an invalid date!\n";
  74.    }
  75.    break;
  76.   case 7:
  77.    {
  78.     if(dob>=1&&dob<=20)
  79.      printf("Your Western Zodiac Sign is Cancer.\n";
  80.     else if(dob>=21&&dob<=31)
  81.      printf("Your Western Zodiac Sign is Leo.\n";
  82.     else
  83.      printf("Your have entered an invalid date!\n";
  84.    }
  85.    break;
  86.   case 8:
  87.    {
  88.     if(dob>=1&&dob<=20)
  89.      printf("Your Western Zodiac Sign is Leo.\n";
  90.     else if(dob>=21&&dob<=31)
  91.      printf("Your Western Zodiac Sign is Virgo.\n";
  92.     else
  93.      printf("Your have entered an invalid date!\n";
  94.    }
  95.    break;
  96.   case 9:
  97.    {
  98.     if(dob>=1&&dob<=20)
  99.      printf("Your Western Zodiac Sign is Virgo.\n";
  100.     else if(dob>=21&&dob<=30)
  101.      printf("Your Western Zodiac Sign is Libra.\n";
  102.     else
  103.      printf("Your have entered an invalid date!\n";
  104.    }
  105.    break;
  106.   case 10:
  107.    {
  108.     if(dob>=1&&dob<=20)
  109.      printf("Your Western Zodiac Sign is Libra.\n";
  110.     else if(dob>=21&&dob<=31)
  111.      printf("Your Western Zodiac Sign is Scorpio.\n";
  112.     else
  113.      printf("Your have entered an invalid date!\n";
  114.    }
  115.    break;
  116.   case 11:
  117.    {
  118.     if(dob>=1&&dob<=20)
  119.      printf("Your Western Zodiac Sign is Scorpio.\n";
  120.     else if(dob>=21&&dob<=30)
  121.      printf("Your Western Zodiac Sign is Sagittarius.\n";
  122.     else
  123.      printf("Your have entered an invalid date!\n";
  124.    }
  125.    break;
  126.   case 12:
  127.    {
  128.     if(dob>=1&&dob<=20)
  129.      printf("Your Western Zodiac Sign is Sagittarius.\n";
  130.     else if(dob>=21&&dob<=31)
  131.      printf("Your Western Zodiac Sign is Capricorn.\n";
  132.     else
  133.      printf("Your have entered an invalid date!\n";
  134.    }
  135.    break;
  136.   default:
  137.    printf("You have entered an invalid month!\n";
  138.    break;
  139.   }
  140.   printf("Enter any key to continue or E to exit.\n";
  141.   scanf("%c",&key);
  142. }while(key!='E');
  143. }
复制代码
我的key出了什么问题?
怎么按了E却loop不停?
回复

使用道具 举报

发表于 3-10-2008 11:12 PM | 显示全部楼层
printf("lease enter your day of birth (01-31): ";
  scanf("%d",&dob);
  printf("lease enter your month of birth (01-12): ";
  scanf("%d",&mob);
  
你忘了打")"在";"的前面,
应该是。。。。birth (01-31): ");
然后把while(key!='E');
换成while(key!='E'||key!='e')看看可以吗?刚才我试了,没有问题。
回复

使用道具 举报

Follow Us
发表于 5-10-2008 03:57 PM | 显示全部楼层
原帖由 choong218 于 3-10-2008 10:16 PM 发表
if(dob>=0321&&dob=0421&&dob



可是我丢掉前面的零也不行哦
回复

使用道具 举报

发表于 5-10-2008 05:33 PM | 显示全部楼层
//A program that prompts user for date of birth, before determining western zodiac sign.
import javax.swing.JOptionPane;
public class Westernzodiacsign
{
    //main method begins execution of Java application
    public static void main(String args[])
    {
        String dob,mob;
        int dob1,mob1;
        
        dob=JOptionPane.showInputDialog("Enter your day of birth(1-31)");
        mob=JOptionPane.showInputDialog("Enter your month of birth(1-12)");
        
        dob1=Integer.parseInt(dob);
        mob1=Integer.parseInt(mob);
        
        if (dob1>=21 && dob1<=31 && mob1==3)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Aries!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
   
        else if (dob1>=1 && dob1<=19 && mob1==4)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Aries!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=21 && dob1<=31 && mob1==5)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Gemini!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=1 && dob1<=21 && mob1==6)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Gemini!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=20 && dob1<=30 && mob1==4)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Taurus!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=1 && dob1<=20 && mob1==5)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Taurus!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=22 && dob1<=30 && mob1==6)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Cancer!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=1 && dob1<=22 && mob1==7)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Cancer!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=23 && dob1<=31 && mob1==7)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Leo!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=1 && dob1<=22 && mob1==8)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Leo!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=23 && dob1<=31 && mob1==8)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Virgo!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=1 && dob1<=22 && mob1==9)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Virgo!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=23 && dob1<=30 && mob1==9)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Libra!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=1 && dob1<=22 && mob1==10)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Libra!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=23 && dob1<=31 && mob1==10)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Scorpio!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=1 && dob1<=21 && mob1==11)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Scorpio!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=22 && dob1<=30 && mob1==11)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Sagittarius!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
        
        else if (dob1>=1 && dob1<=21 && mob1==12)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Sagittarius!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=22 && dob1<=31 && mob1==12)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Capricorn!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=1 && dob1<=19 && mob1==1)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Capricorn!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=20 && dob1<=31 && mob1==1)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Aquarius!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=1 && dob1<=19 && mob1==2)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Aquarius!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=19 && dob1<=29 && mob1==2)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Pisces!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
            
        else if (dob1>=1 && dob1<=20 && mob1==3)
            JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is Pisces!","Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
               
        else
            JOptionPane.showMessageDialog(null,"You Have Entered an Invalid Date of Birth!","Error!",JOptionPane.ERROR_MESSAGE);
            
        System.exit(0);
            
    }//end of method main
}//end of class Westernzodiacsign



solve到了
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 7-10-2008 01:03 AM | 显示全部楼层
原帖由 missing~ 于 5-10-2008 05:33 PM 发表
//A program that prompts user for date of birth, before determining western zodiac sign.
import javax.swing.JOptionPane;
public class Westernzodiacsign
{
    //main method begins execution of Java ...


啊?
这应该是Java吧?
我做的是C Language噢~
不过无论如何,
谢谢你
回复

使用道具 举报

发表于 7-10-2008 01:20 AM | 显示全部楼层
原帖由 蜡笔小烦 于 7-10-2008 01:03 AM 发表


啊?
这应该是Java吧?
我做的是C Language噢~
不过无论如何,
谢谢你


我拿你的来玩下咯,顺便学下。我现在学着java.,多多指导我下,我很弱
回复

使用道具 举报

 楼主| 发表于 7-10-2008 01:23 AM | 显示全部楼层

  1. /*
  2. Homework for chapter 4:
  3. Write a C program that prompt the user for his or her date of birth,
  4. before determining his or her Western Zodiac Sign.
  5. The program must remain in an infinite loop
  6. (prompt the user for his or her date of birth again, after each display of the previous result)
  7. until a unique key is pressed, indicating that the user wishes to exit the program.
  8. */
  9. #include<stdio.h>
  10. void main()
  11. {
  12. int dob;
  13. int mob;
  14. char key;
  15. do
  16. {
  17.   printf("Please enter your day of birth (1-31): ");
  18.   scanf("%d",&dob);
  19.   if(dob>31||dob<1)
  20.   {
  21.    printf("Your have entered an invalid date!\n");
  22.    break;
  23.   }
  24.    
  25.   printf("Please enter your month of birth (1-12): ");
  26.   scanf("%d",&mob);
  27.   if(mob>12||mob<1)
  28.   {
  29.    printf("Your have entered an invalid month!\n");
  30.    break;
  31.   }
  32.   
  33.   switch(mob)
  34.   {
  35.   case 1:
  36.    {
  37.     if(dob>=1&&dob<=20)
  38.      printf("Your Western Zodiac Sign is Capricorn.\n");
  39.     else if(dob>=21&&dob<=31)
  40.      printf("Your Western Zodiac Sign is Aquarius.\n");
  41.     else
  42.      printf("Your have entered an invalid date!\n");
  43.    }
  44.    break;
  45.   case 2:
  46.    {
  47.     if(dob>=1&&dob<=20)
  48.      printf("Your Western Zodiac Sign is Aquarius.\n");
  49.     else if(dob>=21&&dob<=29)
  50.      printf("Your Western Zodiac Sign is Pisces.\n");
  51.     else
  52.      printf("Your have entered an invalid date!\n");
  53.    }
  54.    break;
  55.   case 3:
  56.    {
  57.     if(dob>=1&&dob<=20)
  58.      printf("Your Western Zodiac Sign is Aquarius.\n");
  59.     else if(dob>=21&&dob<=31)
  60.      printf("Your Western Zodiac Sign is Pisces.\n");
  61.     else
  62.      printf("Your have entered an invalid date!\n");
  63.    }
  64.    break;
  65.   case 4:
  66.    {
  67.     if(dob>=1&&dob<=20)
  68.      printf("Your Western Zodiac Sign is Aries.\n");
  69.     else if(dob>=21&&dob<=30)
  70.      printf("Your Western Zodiac Sign is Taurus.\n");
  71.     else
  72.      printf("Your have entered an invalid date!\n");
  73.    }
  74.    break;
  75.   case 5:
  76.    {
  77.     if(dob>=1&&dob<=20)
  78.      printf("Your Western Zodiac Sign is Taurus.\n");
  79.     else if(dob>=21&&dob<=31)
  80.      printf("Your Western Zodiac Sign is Gemini.\n");
  81.     else
  82.      printf("Your have entered an invalid date!\n");
  83.    }
  84.    break;
  85.   case 6:
  86.    {
  87.     if(dob>=1&&dob<=20)
  88.      printf("Your Western Zodiac Sign is Gemini.\n");
  89.     else if(dob>=21&&dob<=30)
  90.      printf("Your Western Zodiac Sign is Cancer.\n");
  91.     else
  92.      printf("Your have entered an invalid date!\n");
  93.    }
  94.    break;
  95.   case 7:
  96.    {
  97.     if(dob>=1&&dob<=20)
  98.      printf("Your Western Zodiac Sign is Cancer.\n");
  99.     else if(dob>=21&&dob<=31)
  100.      printf("Your Western Zodiac Sign is Leo.\n");
  101.     else
  102.      printf("Your have entered an invalid date!\n");
  103.    }
  104.    break;
  105.   case 8:
  106.    {
  107.     if(dob>=1&&dob<=20)
  108.      printf("Your Western Zodiac Sign is Leo.\n");
  109.     else if(dob>=21&&dob<=31)
  110.      printf("Your Western Zodiac Sign is Virgo.\n");
  111.     else
  112.      printf("Your have entered an invalid date!\n");
  113.    }
  114.    break;
  115.   case 9:
  116.    {
  117.     if(dob>=1&&dob<=20)
  118.      printf("Your Western Zodiac Sign is Virgo.\n");
  119.     else if(dob>=21&&dob<=30)
  120.      printf("Your Western Zodiac Sign is Libra.\n");
  121.     else
  122.      printf("Your have entered an invalid date!\n");
  123.    }
  124.    break;
  125.   case 10:
  126.    {
  127.     if(dob>=1&&dob<=20)
  128.      printf("Your Western Zodiac Sign is Libra.\n");
  129.     else if(dob>=21&&dob<=31)
  130.      printf("Your Western Zodiac Sign is Scorpio.\n");
  131.     else
  132.      printf("Your have entered an invalid date!\n");
  133.    }
  134.    break;
  135.   case 11:
  136.    {
  137.     if(dob>=1&&dob<=20)
  138.      printf("Your Western Zodiac Sign is Scorpio.\n");
  139.     else if(dob>=21&&dob<=30)
  140.      printf("Your Western Zodiac Sign is Sagittarius.\n");
  141.     else
  142.      printf("Your have entered an invalid date!\n");
  143.    }
  144.    break;
  145.   case 12:
  146.    {
  147.     if(dob>=1&&dob<=20)
  148.      printf("Your Western Zodiac Sign is Sagittarius.\n");
  149.     else if(dob>=21&&dob<=31)
  150.      printf("Your Western Zodiac Sign is Capricorn.\n");
  151.     else
  152.      printf("Your have entered an invalid date!\n");
  153.    }
  154.    break;
  155.   default:
  156.    printf("You have entered an invalid month!\n");
  157.    break;
  158.   }
  159.   printf("Enter any key to continue or E to exit.\n");
  160.   scanf("%c",&key);
  161. }while(dob!=999);
  162. }
复制代码


不知道那里出了问题
它的output竟然是这样的:
Please enter your day of birth (1-31): 1
Please enter your month of birth (1-12): 2
Your Western Zodiac Sign is Aquarius.
Enter any key to continue or E to exit.
Please enter your day of birth (1-31):

总觉得这coding很多缺陷~
大家帮帮忙。。。
拜托了~
回复

使用道具 举报

 楼主| 发表于 7-10-2008 01:24 AM | 显示全部楼层
原帖由 missing~ 于 7-10-2008 01:20 AM 发表


我拿你的来玩下咯,顺便学下。我现在学着java.,多多指导我下,我很弱


Java还蛮好玩的。
大家一起学习吧~
回复

使用道具 举报

 楼主| 发表于 7-10-2008 01:28 AM | 显示全部楼层
原帖由 choong218 于 3-10-2008 11:12 PM 发表
printf("lease enter your day of birth (01-31): ";
  scanf("%d",&dob);
  printf("lease enter your month of birth (01-12): ";
  scanf("%d",&mob);
  
你忘了打")"在";"的前面,
应该是。。。。birth ( ...


行不通哦~
我刚post了我新改良的
不过还是cacat的
回复

使用道具 举报

 楼主| 发表于 7-10-2008 01:03 PM | 显示全部楼层
  1. /*
  2. Homework for chapter 4:
  3. Write a C program that prompt the user for his or her date of birth,
  4. before determining his or her Western Zodiac Sign.
  5. The program must remain in an infinite loop
  6. (prompt the user for his or her date of birth again, after each display of the previous result)
  7. until a unique key is pressed, indicating that the user wishes to exit the program.
  8. */
  9. #include<stdio.h>
  10. int main()
  11. {
  12. int day;
  13. int month;
  14. char key;
  15. do
  16. {
  17.   printf("lease enter your day of birth: ";
  18.   scanf("%d",&day);
  19.   printf("lease enter your month of birth: ";
  20.   scanf("%d",&month);
  21.   if((day>=20)&&(day<=31)&&(month==1))
  22.    printf("Your Western Zodiac Sign is Aquarius.\n";
  23.   else if((day>=1)&&(day<=18)&&(month==2))
  24.    printf("Your Western Zodiac Sign is Aquarius.\n";
  25.   else if((day>=19)&&(day<29)&&(month==2))
  26.    printf("Your Western Zodiac Sign is Pisces.\n";
  27.   else if((day>=1)&&(day<=20)&&(month==3))
  28.    printf("Your Western Zodiac Sign is Pisces.\n";
  29.   else if((day>=21)&&(day<=31)&&(month==3))
  30.    printf("Your Western Zodiac Sign is Aries.\n";
  31.   else if((day>=1)&&(day<=19)&&(month==4))
  32.    printf("Your Western Zodiac Sign is Aries.\n";
  33.   else if((day>=20)&&(day<=30)&&(month==4))
  34.    printf("Your Western Zodiac Sign is Taurus.\n";
  35.   else if((day>=1)&&(day<=20)&&(month==5))
  36.    printf("Your Western Zodiac Sign is Taurus.\n";
  37.   else if((day>=21)&&(day<=31)&&(month==5))
  38.    printf("Your Western Zodiac Sign is Gemini.\n";
  39.   else if((day>=1)&&(day<=20)&&(month==6))
  40.    printf("Your Western Zodiac Sign is Gemini.\n";
  41.   else if((day>=21)&&(day<=31)&&(month==6))
  42.    printf("Your Western Zodiac Sign is Cancer.\n";
  43.   else if((day>=1)&&(day<=22)&&(month==7))
  44.    printf("Your Western Zodiac Sign is Cancer.\n";
  45.   else if((day>=23)&&(day<=31)&&(month==7))
  46.    printf("Your Western Zodiac Sign is Leo.\n";
  47.   else if((day>=1)&&(day<=22)&&(month==8))
  48.    printf("Your Western Zodiac Sign is Leo.\n";
  49.   else if((day>=23)&&(day<=31)&&(month==8))
  50.    printf("Your Western Zodiac Sign is Virgo.\n";
  51.   else if((day>=1)&&(day<=22)&&(month==9))
  52.    printf("Your Western Zodiac Sign is Virgo.\n";
  53.   else if((day>=23)&&(day<=30)&&(month==9))
  54.    printf("Your Western Zodiac Sign is Libra.\n";
  55.   else if((day>=1)&&(day<=22)&&(month==10))
  56.    printf("Your Western Zodiac Sign is Libra.\n";
  57.   else if((day>=23)&&(day<=31)&&(month==10))
  58.    printf("Your Western Zodiac Sign is Scorpio.\n";
  59.   else if((day>=1)&&(day<=21)&&(month==11))
  60.    printf("Your Western Zodiac Sign is Scorpio.\n";
  61.   else if((day>=22)&&(day<=30)&&(month==11))
  62.    printf("Your Western Zodiac Sign is Sagittarius.\n";
  63.   else if((day>=1)&&(day<=21)&&(month==12))
  64.    printf("Your Western Zodiac Sign is Sagittarius.\n";
  65.   else if((day>=22)&&(day<=31)&&(month==12))
  66.    printf("Your Western Zodiac Sign is Capricorn.\n";
  67.   else if((day>=1)&&(day<=19)&&(month==1))
  68.    printf("Your Western Zodiac Sign is Capricorn.\n";
  69.   else
  70.    printf("Wrong day or month.\n";
  71.   printf("ress any key to continue or e to exit: ";
  72.   scanf(" %c",&key);  
  73.   printf("\n";
  74.   }while(key!='e');
  75. return 0;
  76. }
复制代码

Please enter your day of birth: 20
Please enter your month of birth: 4
Your Western Zodiac Sign is Taurus.
Press any key to continue or e to exit: w

Please enter your day of birth: 33
Please enter your month of birth: 20
Wrong day or month.
Press any key to continue or e to exit: e

Press any key to continue_


基本上是没问题了
可是我在想要怎么让显示成以下这样呢?


Please enter your day of birth: 33
Wrong day.
Press any key to continue or e to exit: w

Please enter your day of birth: 3
Please enter your month of birth: 33
Wrong month.
Press any key to continue or e to exit: w

Please enter your day of birth: 20
Please enter your month of birth: 4
Your Western Zodiac Sign is Taurus.
Press any key to continue or e to exit: e

Press any key to continue_

[ 本帖最后由 蜡笔小烦 于 7-10-2008 01:07 PM 编辑 ]
回复

使用道具 举报

发表于 7-10-2008 02:19 PM | 显示全部楼层
else
   printf("Wrong day or month.\n";
  printf("ress any key to continue or e to exit: ";
  scanf(" %c",&key);  
  printf("\n";
  }while(key!='e');
试下这样
else(
if(day>31)
printf(“wrong date”);
else if (month>12)
printf("wrong month");
)
回复

使用道具 举报

发表于 7-10-2008 02:23 PM | 显示全部楼层
再加一个
else if(day>31 && month>12)
printf("wrong date & wrong month");
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 7-10-2008 08:09 PM | 显示全部楼层
原帖由 政治旁观者 于 7-10-2008 02:23 PM 发表
再加一个
else if(day>31 && month>12)
printf("wrong date & wrong month");


这我知道
可是要怎么把它在wrong input后直接显示" Press any key to continue or e to exit: w "?
回复

使用道具 举报

发表于 8-10-2008 03:16 PM | 显示全部楼层

回复 17# 蜡笔小烦 的帖子

else(
if(day>31)
printf(“wrong date”);
else if (month>12)
printf("wrong month");
else if(day>31 && month>12)
printf("wrong date & wrong month");
)
printf("press any key to continue or e to exit: ";
  scanf(" %c",&key);  
  printf("\n";
  }while(key!='e');
return 0;
}
这样应该可以了
回复

使用道具 举报

 楼主| 发表于 11-10-2008 01:53 PM | 显示全部楼层
原帖由 政治旁观者 于 8-10-2008 03:16 PM 发表
else(
if(day>31)
printf(“wrong date”);
else if (month>12)
printf("wrong month";
else if(day>31 && month>12)
printf("wrong date & wrong month";
)
printf("press any key to continue or e to e ...


谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 04:36 AM , Processed in 0.149275 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表