|
查看: 1021|回复: 8
|
C Language: Project+ing
[复制链接]
|
|
|
- if (month[i]==1)
- {
- back:
- printf("Please enter the day of your birth (1-31): ");
- scanf("%d",&day[i]);
- if (day[i]<=19)
- {
- printf("%s,your birthday details:\n",name[i]);
- printf("Your are born on %d January %d.\n",day[i],year[i]);
- calAge();
- chineseYear();
- printf("You are a CAPRICORN.\n");
- printf("Your BirthStone is GARNET.\n");
- printf("\n");
- }
- else if (day[i]>19&&day[i]<=31)
- {
- printf("%s,your birthday details:\n",name[i]);
- printf("Your are born on %d January %d.\n",day[i],year[i]);
- calAge();
- chineseYear();
- printf("You are an AQUARIUS.\n");
- printf("Your BirthStone is GARNET.\n");
- printf("\n");
- }
- else
- {
- printf("Invalid day.Please enter again.\n");
- goto back;
- }
- }
复制代码
没有error
output的时候
Enter Birthday Details For User #1? (Y/N): y
Please enter your name:
Please enter the year of your birth (1908-2008):
名字输入被skip掉了。。。
试过用gets不过还是不行。。。
怎么办?
大家帮帮忙看一下
谢谢。。。
我没放完整的code上来
因为超过字限了。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 19-10-2008 01:10 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 19-10-2008 02:10 PM
|
显示全部楼层
- import javax.swing.JOptionPane;
- public class Horoscope {
- public static void main(String args[]) {
- String horos[] = { "Capricorn", "Aquarius", "isces", "Aries",
- "Taurus", "Gemini", "Cancer", "Leo",
- "Virgo", "Libra", "Scorpio", "Sagittarius" };
-
- int month = promptMOB();
- int day = promptDOB(month);
-
- if(day <= 20){
- --month;
- month = month %12;
- System.out.println(month);
- }
-
- JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is "+horos[month%12] +"!",
- "Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
- System.exit(0);
- }
-
- public static int promptMOB(){
-
- String mob=JOptionPane.showInputDialog("Enter your month of birth(1-12)";
- int month=Integer.parseInt(mob);
-
- if(month>= 1 && month<= 12)
- return month;
- else{
- JOptionPane.showMessageDialog(null,"You Have Entered an Invalid Month of Birth!",
- "Error!",JOptionPane.ERROR_MESSAGE);
- return promptMOB();
- }
- }
-
- public static int promptDOB(int a){
-
- int maxDay[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
- String dob=JOptionPane.showInputDialog("Enter your day of birth(1-31)";
- int day=Integer.parseInt(dob);
-
-
-
- if(day <= maxDay[a-1])
- return day;
- else{
- JOptionPane.showMessageDialog(null,"You Have Entered an Invalid Date of Birth!",
- "Error!",JOptionPane.ERROR_MESSAGE);
- return promptDOB(a);
- }
- }
- }
复制代码
我用java写的
蛮多redundant code的, 没时间tune他
但run的到, 暂时没有logical error
希望你能明白他的flow
你是不是UNIMAS的?
[ 本帖最后由 晨天 于 19-10-2008 02:31 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 19-10-2008 06:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 19-10-2008 06:33 PM
|
显示全部楼层
-
- #include <stdio.h>
- #include <string.h>
- #define SIZE 100
- int chineseYear();
- int calAge();
- int i,birthYear[SIZE], birthMonth[SIZE], birthDay[SIZE],currentYear[SIZE],currentMonth[SIZE],currentDay[SIZE];
- char opt,name[SIZE][20];
- int years[SIZE];
- int months[SIZE];
- int days[SIZE];
- void main()
- {
- for(i=0;i<SIZE;i++)
- {
- printf("Please enter your name: ");
- scanf("%s",&name[i]);
- start:
- printf("Please enter current year: ");
- scanf("%d",¤tYear[i]);
- printf("Please enter current month: ");
- scanf("%d",¤tMonth[i]);
-
- printf("Please enter current day: ");
- scanf("%d",¤tDay[i]);
- printf("Please enter the year of your birth (1908-2008): ");
- scanf("%d",&birthYear[i]);
- printf("Please enter the month of your birth (1-12): ");
- scanf("%d",&birthMonth[i]);
- if (birthMonth[i]==1)
- {
- back:
- printf("Please enter the day of your birth (1-31): ");
- scanf("%d",&birthDay[i]);
- printf("\n");
- if (birthDay[i]<=19)
- {
- printf("\n%s,your birthday details:\n",name[i]);
- printf("Your are born on %d January %d.\n",birthDay[i],birthYear[i]);
- calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
- chineseYear();
- printf("You are a CAPRICORN.\n");
- printf("Your BirthStone is GARNET.\n");
- printf("\n");
- }
- //skipped................................................//
- }
- }
- int calAge(int currentYear[],int currentMonth[],int currentDay[],int birthYear[],int birthMonth[],int birthDay[])
- {
- for(i=0;i<SIZE;i++)
- {
- years[i]=currentYear[i]-birthYear[i];
- if((birthMonth[i]>currentMonth[i])||((birthMonth[i]==currentMonth[i])&&(birthDay[i]>currentDay[i])))
- {
- years[i]=years[i]-1;
- }
- months[i]=currentMonth[i]-birthMonth[i];
- if(birthDay[i]>currentDay[i])
- {
- months[i]=months[i]-1;
- }
- days[i]=currentDay[i]-birthDay[i];
- if(birthDay[i]>currentDay[i])
- {
- days[i]=(currentDay[i]+30)-birthDay[i];
- }
- printf("You are %d years, %d months, %d days old.\n",years[i],months[i],days[i]);
- }
- return 0;
- }
-
复制代码
有些code我没放上来
我只是想focus在passing array
不确定要怎么pass。。。
请大家赐教~
谢谢~
[ 本帖最后由 蜡笔小烦 于 19-10-2008 07:23 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 19-10-2008 10:17 PM
|
显示全部楼层
原帖由 蜡笔小烦 于 19-10-2008 06:33 PM 发表 
#include
#include
#define SIZE 100
int chineseYear();
int calAge();
int i,birthYear, birthMonth, birthDay,currentYear,currentMonth,currentDay;
char opt,name[20];
int years;
int months;
...
calAge(currentYear,currentMonth,currentDay,birthYear,birthMonth,birthDay);
试试看。
[ 本帖最后由 NewEraPenang 于 19-10-2008 10:18 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 19-10-2008 10:38 PM
|
显示全部楼层
原帖由 NewEraPenang 于 19-10-2008 10:17 PM 发表 
试试看。
啊?
怎么会是这样子的呢?
我试了
百多个error
绝大多数是关于到array的。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 19-10-2008 11:19 PM
|
显示全部楼层
array passing syntax- #include <stdio.h>
- void print_array( int array[]);
- int main()
- {
- int a[] = {2,3,4,5,6};
- print_array( a ); // passing array to function
- return 0;
- }
- void print_array( int array[])
- {
- int i;
- for( i = 0; i < 5 ; i++ )
- printf("array[%d] = %d\n", i, array[i]);
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 20-10-2008 03:42 PM
|
显示全部楼层
原帖由 onlylonly 于 19-10-2008 11:19 PM 发表 
array passing syntax#include
void print_array( int array[]);
int main()
{
int a[] = {2,3,4,5,6};
print_array( a ); // passing array to function
return 0;
}
void print_ ...
谢谢
passing array的问题解决了
只是现在又有新的问题了
就是在1st round input 的时候一切正常
而second round 的时候却走样了
####################################;
##### Birthday Calculator Beta Version #####;
####################################
Enter birthday details for user #1? (Y/N): Y
Please enter your name: Xiao Wan Zi
Please enter current year: 2008
Please enter current month: 10
Please enter current day: 20
Please enter your birth year: 1985
Please enter your birth month: 4
Please enter your birth day: 20
Xiao,your birthday details:
You are born on 20 April 1985.
You are born in the Chinese year of the Ox.
You are a TAURUS.
Your birthstone is DIAMOND.
You are 23 years,6 months,0 days old.
180 days left for your next birthday.
####################################;
##### Birthday Calculator Beta Version #####;
####################################
Enter birthday details for user #2? (Y/N): Invalid Input.Please try to enter again.
Enter birthday details for user #2? (Y/N):
由于coding太长了
这里放不下
所以我放上网了
希望大家帮我看看。。。
http://www.uploading.com/files/SHPO821E/Copy_of_Copy_of_BirthdayCal.c.html
拜托了。。。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|