Thread: tell me what u think

  1. #1
    Registered User
    Join Date
    Apr 2012
    Location
    Kingston, Jamaica, Jamaica
    Posts
    9

    tell me what u think

    PHP Code:
    [code]
    #include<stdio.h>
    //#include<conio.h>
     
     
    int main(void){
     
    char yndalarm;
     
    int formathhhm,mmmtmonthpyyb,dd,day,adr,i;  
     
    int nummin,a,sec,hours,daysw,daysm,year=2012//initializing variables
      

      

     
    system("pause"); //decoration
     
    system("cls");   // Clear screen
     //printf the optoion to either secect a clock or a stop watch
     
    printf("Please enter the operation u desire: \n\n--->\t'1' for <<< CLOCK >>>: \n\t\tOr\n--->\t'2': for STOP WATCH:\n");
     
    scanf("%d", &num); //read the inputed integer as num
     
    system("cls"); // Clear screen
     
    system("pause");  //decoration     
     
     
    switch(num){  // to place the inputed value of num into different task or case
      
     
    case 1:   //   task 1, the clock 
     
     
    printf("please enter format 24 0r 12\n");
     
    scanf("%d",&format);
     
    printf("Set time: hours/min/\n");
     
    scanf("%d%d",&hh,&mm);
     
    printf("Set date: dd/mm/yyyy\n ");
     
    scanf("%d%d%d",&dd,&mt,&yy);
     
    printf("Set day, by sececting the number which suit the say \n1:\tSun\n2:\tMon\n3:\tTue\n4:\tWed\n5:\tThur\n6:\tFri\n7:\tSat\n :");
     
    scanf("%d",&p); 
     
     
    system("pause");
     
    system("cls");
     
    printf("y to set alarm.\n n to set alarm.\n:");
     
    scanf("%s", &alarm);
     
    system("cls");
     switch(
    alarm){
                
     case 
    'y':printf("Set Alarm day:\ne\tEvery day\no\tOnly once\nl\t select day\n:");
          
    scanf("%s",&d);
          switch(
    d){
             case 
    'e'printf("Every Day\n");
              
    b=7;
          break;
                   
          case 
    'o'printf("Only once\n");
              
    b=1;
          break;
          
             case 
    'l'printf("Select Days\n-1:\tTo end input\n1:\tSun\n2:\tMon\n3:\tTue\n4:\tWed\n5:\tThur\n6:\tFri\n7:\tSat\n :");
              
    printf("Set day, by sececting the number which suit the say\n");
          
    b=0;
          while(
    i!=-1){
                
    scanf("%d", &i);
                
            
    b++;}
          break;             
           case 
    '\n':
          case 
    '\t':                      
           case 
    ' ':
           break;
           default:
    printf("\awrong integer\n");
                
    printf("Set Alarm day:\ne\tEvery day\no\tOnly once\nl\t select day\n:");
                  
    scanf("%s",&d);
           break;}
              
    printf("set Timehh:mm\n");
              
    scanf("%d%d", &h,&m);     
              
           
    system("pause");  
     break;
     
     case 
    'n'printf("No alarm \n");
     break;
     case 
    '\n':
     case 
    '\t':                      
     case 
    ' ':
     break;
     default: 
    printf("Wrong Character entered");
     
    printf("y to set alarm.\n n to set alarm.\n:");
     
    scanf("%c", &alarm);
     break; 
    }

     

      
     for(
    year=yyyear<=10000year++){ //calculate the yeas
     
     
    for(month=mtmonth<=12month++){ //calculate the days of the week
      
     
    if(mt==|| mt==|| mt==|| mt==|| mt==|| mt==10 || mt==12) {
     
    r=31;
     } else
     if(
    mt==|| mt==|| mt==|| mt==|| mt==11) {
     
    r=30;
     } else
     if(
    mt==2){
     
    r=29;}
     
     for(
    daysm=dddaysm<=rdaysm++){ //calculate the days of the month
      
     
    for(hours=hhhours<formathours++){ // calculate the hours
     
     
    for(min=mmmin<=59min++){   // calculate the minutes  
     
     
    for(sec=0sec<15;sec++){   //calculate the sec  
     
    if(h==hh && m==mm && b>=1){
     
    printf("\a\a\a\a");
     
    b-=1;}
     
     
    // print the hours and minutes        
     
    for(a=0a<=1;printf("\n\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\t$$$  *=*=*=*=*     *=*=*=*=*  $$$\n\t$$$ *=*=*=*=*=*   *=*=*=*=*=* $$$\n\t$$$*=*=*=*=*=*=* *=*=*=*=*=*=*$$$\n\t$$$*=*=*=*"a++)){ 
     
    hours>9printf("    %d:",hours):printf("     %d:",hours);
     
    min>9printf("%d   =*=*=*=*$$$\n",min):printf("%d    =*=*=*=*$$$\n"min);
     
    printf("       +$$$ *=*=*=      ");  //decoration
     
    sec>9printf("%d    *=*=*=* $$$+\n"sec):printf("%d     *=*=*=* $$$+\n"sec); //print the seconds
     
    printf("      ++$$$  *=*=* ");   //decoration
     
     
    switch(p){
      case 
    1:  printf("  SUNDAY  ");

      break;
      case 
    2:  printf("  MONDAY  ");
      break;
      case 
    3:  printf("  TUESDAY "); 
      break;
      case 
    4:  printf("WEDNESDAY ");
      break;
      case 
    5:  printf(" THURSDAY ");
      break;
      case 
    6:  printf("  FRIDAY  ");
      break;
      case 
    7:  printf(" SATURDAY ");
      break; 
      case 
    '\n':
      case 
    '\t':
      case 
    ' ':
      break; 
      default: 
    p=;
      break; 
    }
      
    printf(" =*=*=*  $$$++\n");
     
    printf("      ++$$$   *=*= ");
     switch(
    month){ 
      case 
    1:          
      
    printf("JAN");
      break;
      break;  
      case 
    2:
      
    printf("FEB");
      break;  
      case 
    3:
      
    printf("MAR");
      break;  
      case 
    4:
      
    printf("APL");
      break;
      
      case 
    5:
      
    printf("MAY");
      break;
      case 
    6:
      
    printf("JUN");
      break;
      case 
    7:
      
    printf("JUL");
      break;  
      case 
    8:
      
    printf("AUG");
      break;
      case 
    9:
      
    printf("SEP");
      break;  
      case 
    10:
      
    printf("OCT");
      break;  
      case 
    11:
      
    printf("NOV");
      break;  
      case 
    12:
      
    printf("DEC");
      break;
    }
     
    daysm>9?printf(" %d "daysm) : printf(" %d "daysm);
     
    daysm>9?printf("%d*=*=*   $$$++\n",year):printf("%d *=*=*   $$$++\n",year);
     
    printf("      ++$$$    *=*=*=*=*=*=*=*=*=*    $$$++\n");
     
    printf("      ++$$$     *=*=*=*=*=*=*=*=*     $$$++\n");
     
    printf("      ++$$$\t *=*=*=*=*=*=*=*      $$$++\n");
     
    printf("       +$$$\t  *=*=*=*=*=*=*       $$$+\n");
     
    printf("\t$$$\t   *=*=*=*=*=*        $$$\n");
     
    printf("\t$$$\t    *=*=*=*=*         $$$\n");
     
    printf("\t$$$\t     *=*=*=*          $$$\n");
     
    printf("\t$$$\t      *=*=*           $$$\n");
     
    printf("\t$$$\t        *          $$$\n");
     
    printf("\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
     
    printf("\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");

     
    system("cls");  // clear screen      
     

    }  

    mm=0;    
    printf("\a"); 


    hh=0;
    if(
    daysm==r){
    dd=1;}
    p+=1
    }
    printf("\a");
    if(
    month==12);{
    mt=1;}
    }
    }
    system("pause");
     
    break;   
    // next task
     
    case 2:   //The stop watch
                   
    for(hours=0hours<90hours++){
    for(
    min=0min<60min++){
    for(
    sec=0sec<60;sec++){       
    for(
    a=1a<15;printf("\n\t*=*=*=*=*=*=*=*=*=*=*\n\t*=*=*=*=*=*=*=*=*=*=*\n\t*=*")){
    hours>9?printf("%d",hours): printf(" %d",hours);
    min>9?printf(" :%d",min): printf(" : %d",min);
    sec>9?printf(" :%d",sec): printf(" : %d",sec);                       
    a>9?printf(" :%d",a++): printf(" : %d",a++);
    printf("=*=*\n\t*=*=*=*=*=*=*=*=*=*=*\n\t*=*=*=*=*=*=*=*=*=*=*\n\t");
    system("cls");
    }
    }
    }
    }
    break;


    case 
    '\n':
    case 
    '\t':
    case 
    ' ':
    break;

    default: 
    printf("wrong integer entered please reenter");
    break;
    }
     
    getch();
     return 
    0;
     } 
    [/
    code

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Is there any reason you just dumped a bunch of code here (tagged wrong) with no question or other text of any kind?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    I think you're in the wrong line of learning/work.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  4. #4
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Indentation - Awful even when present.
    Variable naming - dubious and confusing.

    Massive overuse of the "system" command with third-party utilities.
    Overuse of the ternary operator (? and : ) where if's would make things clearer (e.g. "daysm>9?printf(" %d ", daysm) : printf(" %d ", daysm);")
    Why does it say "PHP code" in your post?
    Horrible printf multi-line/multi-tab/"lines" built up via large strings/etc. formatting (I assume to make the output pretty)
    printf("\a\a\a\a") - Really? Multiple terminal beeps?
    Inefficient conversion of month to month name (could you not just have an array of 12 strings and pick one out directly by index instead of yet-another switch statement?)

    Seriously, I'm scared to put that into my compiler in case there's something hidden in there that I *don't* want to run.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  5. #5
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    My compiler gives this too:

    ..\test.c:12: warning: implicit declaration of function 'system'
    ..\test.c:113: warning: too many arguments for format
    ..\test.c:249: warning: implicit declaration of function 'getch'
    ..\test.c:7: warning: unused variable 'daysw'
    ..\test.c:6: warning: unused variable 'ad'
    ..\test.c:6: warning: unused variable 'day'
    ..\test.c:5: warning: unused variable 'n'
    ..\test.c:5: warning: unused variable 'y'
    ..\test.c:6: warning: 'b' may be used uninitialized in this function
    ..\test.c:6: warning: 'r' may be used uninitialized in this function

    You obviously DON'T compile with any sorts of warnings on, or don't care about them if you do. And you're missing at least one header but your compiler might just be including that by default (mine didn't, hence the "implicit declaration" warnings).

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    As well as what everyone else said, there's still a lot wrong with your code. For example:

    Code:
    hours>9?printf("%d",hours): printf(" %d",hours);
    This is awful. You do know about printf format specifiers, right?

    Code:
    system("pause"); //decoration
    Not only is this non-portable (use one of these to pause), it's clearly not for "decorating" your program.

    You really also need to split out your code into functions. Make one for the stopwatch, one for the timer, and one to get user input. You could even try passing a struct of month/day/year/etc, once you get it from the user.

Popular pages Recent additions subscribe to a feed