|
查看: 908|回复: 18
|
C Language : 请大家进来帮我debug一下 [已解决]
[复制链接]
|
|
|
- /*
- Homework for chapter 4:
- Write a C program that prompt the user for his or her date of birth,
- before determining his or her Western Zodiac Sign.
- The program must remain in an infinite loop
- (prompt the user for his or her date of birth again, after each display of the previous result)
- until a unique key is pressed, indicating that the user wishes to exit the program.
- */
- #include<stdio.h>
- void main()
- {
- int dob;
- do
- {
- printf("lease enter your date of birth (in form mmdd) or 123 to exit : ";
- scanf("%d",&dob);
- 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";
- else if(dob>=0521&&dob<=0620)
- printf("Your Western Zodiac Sign is Gemini.\n";
- else if(dob>=0621&&dob<=0720)
- printf("Your Western Zodiac Sign is Cancer.\n";
- else if(dob>=0721&&dob<=0820)
- printf("Your Western Zodiac Sign is Leo.\n";
- else if(dob>=0821&&dob<=0920)
- printf("Your Western Zodiac Sign is Virgo.\n";
- else if(dob>=0921&&dob<=1020)
- printf("Your Western Zodiac Sign is Libra.\n";
- else if(dob>=1021&&dob<=1120)
- printf("Your Western Zodiac Sign is Scorpio.\n";
- else if(dob>=1121&&dob<=1220)
- printf("Your Western Zodiac Sign is Sagittarius.\n";
- else if(dob>=1221&&dob<=0120)
- printf("Your Western Zodiac Sign is Capricorn.\n";
- else if(dob>=0121&&dob<=0220)
- printf("Your Western Zodiac Sign is Aquarius.\n";
- else if(dob>=0221&&dob<=0320)
- printf("Your Western Zodiac Sign is Pisces.\n";
- }while(dob!=123);
- }
复制代码 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 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 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
|
显示全部楼层
我的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')看看可以吗?刚才我试了,没有问题。 |
|
|
|
|
|
|
|
|
|
|
发表于 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到了 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 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:23 AM
|
显示全部楼层
不知道那里出了问题
它的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
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 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
|
显示全部楼层
- /*
- Homework for chapter 4:
- Write a C program that prompt the user for his or her date of birth,
- before determining his or her Western Zodiac Sign.
- The program must remain in an infinite loop
- (prompt the user for his or her date of birth again, after each display of the previous result)
- until a unique key is pressed, indicating that the user wishes to exit the program.
- */
- #include<stdio.h>
- int main()
- {
- int day;
- int month;
- char key;
- do
- {
- printf("lease enter your day of birth: ";
- scanf("%d",&day);
- printf("lease enter your month of birth: ";
- scanf("%d",&month);
- if((day>=20)&&(day<=31)&&(month==1))
- printf("Your Western Zodiac Sign is Aquarius.\n";
- else if((day>=1)&&(day<=18)&&(month==2))
- printf("Your Western Zodiac Sign is Aquarius.\n";
- else if((day>=19)&&(day<29)&&(month==2))
- printf("Your Western Zodiac Sign is Pisces.\n";
- else if((day>=1)&&(day<=20)&&(month==3))
- printf("Your Western Zodiac Sign is Pisces.\n";
- else if((day>=21)&&(day<=31)&&(month==3))
- printf("Your Western Zodiac Sign is Aries.\n";
- else if((day>=1)&&(day<=19)&&(month==4))
- printf("Your Western Zodiac Sign is Aries.\n";
- else if((day>=20)&&(day<=30)&&(month==4))
- printf("Your Western Zodiac Sign is Taurus.\n";
- else if((day>=1)&&(day<=20)&&(month==5))
- printf("Your Western Zodiac Sign is Taurus.\n";
- else if((day>=21)&&(day<=31)&&(month==5))
- printf("Your Western Zodiac Sign is Gemini.\n";
- else if((day>=1)&&(day<=20)&&(month==6))
- printf("Your Western Zodiac Sign is Gemini.\n";
- else if((day>=21)&&(day<=31)&&(month==6))
- printf("Your Western Zodiac Sign is Cancer.\n";
- else if((day>=1)&&(day<=22)&&(month==7))
- printf("Your Western Zodiac Sign is Cancer.\n";
- else if((day>=23)&&(day<=31)&&(month==7))
- printf("Your Western Zodiac Sign is Leo.\n";
- else if((day>=1)&&(day<=22)&&(month==8))
- printf("Your Western Zodiac Sign is Leo.\n";
- else if((day>=23)&&(day<=31)&&(month==8))
- printf("Your Western Zodiac Sign is Virgo.\n";
- else if((day>=1)&&(day<=22)&&(month==9))
- printf("Your Western Zodiac Sign is Virgo.\n";
- else if((day>=23)&&(day<=30)&&(month==9))
- printf("Your Western Zodiac Sign is Libra.\n";
- else if((day>=1)&&(day<=22)&&(month==10))
- printf("Your Western Zodiac Sign is Libra.\n";
- else if((day>=23)&&(day<=31)&&(month==10))
- printf("Your Western Zodiac Sign is Scorpio.\n";
- else if((day>=1)&&(day<=21)&&(month==11))
- printf("Your Western Zodiac Sign is Scorpio.\n";
- else if((day>=22)&&(day<=30)&&(month==11))
- printf("Your Western Zodiac Sign is Sagittarius.\n";
- else if((day>=1)&&(day<=21)&&(month==12))
- printf("Your Western Zodiac Sign is Sagittarius.\n";
- else if((day>=22)&&(day<=31)&&(month==12))
- printf("Your Western Zodiac Sign is Capricorn.\n";
- else if((day>=1)&&(day<=19)&&(month==1))
- printf("Your Western Zodiac Sign is Capricorn.\n";
- 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');
- return 0;
- }
复制代码
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"); |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 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
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|