佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1021|回复: 8

C Language: Project+ing

[复制链接]
发表于 19-10-2008 01:04 PM | 显示全部楼层 |阅读模式

  1.    if (month[i]==1)
  2.    {
  3.     back:
  4.     printf("Please enter the day of your birth (1-31): ");
  5.     scanf("%d",&day[i]);
  6.     if (day[i]<=19)
  7.     {
  8.      printf("%s,your birthday details:\n",name[i]);
  9.      printf("Your are born on %d January %d.\n",day[i],year[i]);
  10.      calAge();
  11.      chineseYear();
  12.      printf("You are a CAPRICORN.\n");
  13.      printf("Your BirthStone is GARNET.\n");
  14.      printf("\n");
  15.     }
  16.     else if (day[i]>19&&day[i]<=31)
  17.     {
  18.      printf("%s,your birthday details:\n",name[i]);
  19.      printf("Your are born on %d January %d.\n",day[i],year[i]);
  20.      calAge();
  21.      chineseYear();
  22.      printf("You are an AQUARIUS.\n");
  23.      printf("Your BirthStone is GARNET.\n");     
  24.      printf("\n");
  25.     }
  26.     else
  27.     {
  28.      printf("Invalid day.Please enter again.\n");
  29.      goto back;
  30.     }
  31.    }
复制代码


没有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上来
因为超过字限了。。。
回复

使用道具 举报


ADVERTISEMENT

发表于 19-10-2008 01:10 PM | 显示全部楼层
please read this post =) http://cforum1.cari.com.my/viewthread.php?tid=1375601&amp;extra=page%3D1
回复

使用道具 举报

发表于 19-10-2008 02:10 PM | 显示全部楼层
  1. import javax.swing.JOptionPane;
  2. public class Horoscope {
  3.     public static void main(String args[]) {
  4.      String horos[] = { "Capricorn", "Aquarius", "isces", "Aries",  
  5.           "Taurus", "Gemini", "Cancer", "Leo",
  6.           "Virgo", "Libra", "Scorpio", "Sagittarius"  };
  7.               
  8.      int month = promptMOB();
  9.      int day = promptDOB(month);
  10.         
  11.         if(day <= 20){
  12.          --month;
  13.          month = month %12;
  14.          System.out.println(month);
  15.         }
  16.          
  17.         JOptionPane.showMessageDialog(null,"Your Western Zodiac Sign is "+horos[month%12] +"!",
  18.             "Your Zodiac!",JOptionPane.INFORMATION_MESSAGE);
  19.   System.exit(0);
  20.     }   
  21.          
  22.      public static int promptMOB(){
  23.    
  24.      String mob=JOptionPane.showInputDialog("Enter your month of birth(1-12)";
  25.      int month=Integer.parseInt(mob);
  26.      
  27.      if(month>= 1 && month<= 12)
  28.      return month;
  29.      else{
  30.      JOptionPane.showMessageDialog(null,"You Have Entered an Invalid Month of Birth!",
  31.              "Error!",JOptionPane.ERROR_MESSAGE);
  32.      return promptMOB();
  33.      }
  34.      }
  35.      
  36.      public static int promptDOB(int a){
  37.    
  38.      int maxDay[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  39.      
  40.      String dob=JOptionPane.showInputDialog("Enter your day of birth(1-31)";
  41.      int day=Integer.parseInt(dob);
  42.      
  43.      
  44.      
  45.      if(day <= maxDay[a-1])
  46.      return day;
  47.      else{
  48.      JOptionPane.showMessageDialog(null,"You Have Entered an Invalid Date of Birth!",
  49.              "Error!",JOptionPane.ERROR_MESSAGE);
  50.      return promptDOB(a);
  51.      }
  52.      }
  53. }
复制代码


我用java写的
蛮多redundant code的, 没时间tune他
但run的到, 暂时没有logical error
希望你能明白他的flow

你是不是UNIMAS的?

[ 本帖最后由 晨天 于 19-10-2008 02:31 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 19-10-2008 06:29 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", "Gemi ...


不好意思承认
丢大学的脸
回复

使用道具 举报

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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #define SIZE 100
  4. int chineseYear();
  5. int calAge();
  6. int i,birthYear[SIZE], birthMonth[SIZE], birthDay[SIZE],currentYear[SIZE],currentMonth[SIZE],currentDay[SIZE];
  7. char opt,name[SIZE][20];
  8. int years[SIZE];
  9. int months[SIZE];
  10. int days[SIZE];
  11. void main()
  12. {
  13. for(i=0;i<SIZE;i++)
  14. {
  15.    printf("Please enter your name: ");
  16.    scanf("%s",&name[i]);   
  17.    start:
  18.    printf("Please enter current year: ");
  19.    scanf("%d",&currentYear[i]);
  20.    printf("Please enter current month: ");
  21.    scanf("%d",&currentMonth[i]);
  22.    
  23.    printf("Please enter current day: ");
  24.    scanf("%d",&currentDay[i]);
  25.    printf("Please enter the year of your birth (1908-2008): ");
  26.    scanf("%d",&birthYear[i]);
  27.    printf("Please enter the month of your birth (1-12): ");
  28.    scanf("%d",&birthMonth[i]);
  29.    if (birthMonth[i]==1)
  30.    {
  31.     back:
  32.     printf("Please enter the day of your birth (1-31): ");
  33.     scanf("%d",&birthDay[i]);
  34.     printf("\n");
  35.     if (birthDay[i]<=19)
  36.     {
  37.      printf("\n%s,your birthday details:\n",name[i]);
  38.      printf("Your are born on %d January %d.\n",birthDay[i],birthYear[i]);
  39.      calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
  40.      chineseYear();
  41.      printf("You are a CAPRICORN.\n");
  42.      printf("Your BirthStone is GARNET.\n");
  43.      printf("\n");
  44.     }
  45.     //skipped................................................//
  46. }
  47. }
  48. int calAge(int currentYear[],int currentMonth[],int currentDay[],int birthYear[],int birthMonth[],int birthDay[])
  49. {
  50. for(i=0;i<SIZE;i++)
  51. {
  52.   years[i]=currentYear[i]-birthYear[i];
  53.   if((birthMonth[i]>currentMonth[i])||((birthMonth[i]==currentMonth[i])&&(birthDay[i]>currentDay[i])))
  54.   {
  55.    years[i]=years[i]-1;
  56.   }
  57.   months[i]=currentMonth[i]-birthMonth[i];
  58.   if(birthDay[i]>currentDay[i])
  59.   {
  60.    months[i]=months[i]-1;
  61.   }
  62.   days[i]=currentDay[i]-birthDay[i];
  63.   if(birthDay[i]>currentDay[i])
  64.   {
  65.    days[i]=(currentDay[i]+30)-birthDay[i];
  66.   }
  67.   printf("You are %d years, %d months, %d days old.\n",years[i],months[i],days[i]);
  68. }
  69. return 0;
  70. }

复制代码


有些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 编辑 ]
回复

使用道具 举报

Follow Us
 楼主| 发表于 19-10-2008 10:38 PM | 显示全部楼层
原帖由 NewEraPenang 于 19-10-2008 10:17 PM 发表





试试看。


啊?
怎么会是这样子的呢?
我试了
百多个error
绝大多数是关于到array的。。。
回复

使用道具 举报

发表于 19-10-2008 11:19 PM | 显示全部楼层
array passing syntax
  1. #include <stdio.h>

  2. void print_array( int array[]);

  3. int main()
  4. {
  5.     int a[] = {2,3,4,5,6};

  6.     print_array( a ); // passing array to function

  7.     return 0;

  8. }

  9. void print_array( int array[])
  10. {
  11.     int i;

  12.     for( i = 0; i < 5 ; i++ )
  13.         printf("array[%d] = %d\n", i, array[i]);

  14. }
复制代码
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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

拜托了。。。
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


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

GMT+8, 22-12-2025 06:10 PM , Processed in 0.161769 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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