1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

love meter

Discussion in 'C' started by amanbaua, Sep 5, 2009.

  1. amanbaua

    amanbaua New Member

    Joined:
    Aug 23, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    /*dis is a love meter program in c
    it is based on "FLAMES" 
    where
    F-FLAMES
    L-LOVE
    A-ADORABLE
    M-MARRIAGE
    E-ENEMITY
    S-SISTER
    so just enter ur first name
    n den ur partner's name
    and see the result*/
    
    #include"stdio.h"
    #include"conio.h"
    #include"string.h"
    void main()
    {
      printf("THIS IS A RELATION METER WHICH SHOWS YOUR RELATION WID UR PARTNER\n");
      printf("\n");
      char yn[100],pn[100];
      char a[6]={'f','l','a','m','e','s'};
      int i,j,p=0,len=0,len1=0,t,t1,nl,count,sz=6,nl1;
      printf("enter your name:");
      gets(yn);
      printf("\nenter ur love partner's name:");
      gets(pn);
      int l=strlen(yn);
      int l1=strlen(pn);
      for(i=0;i<l;i++)
      {
         t=yn[i];
        for(j=0;j<l1;j++)
        {
            t1=pn[j];
            if(t==t1)
            {
                 t=0;
              yn[i]=0;
              pn[j]=0;
             }
         }
        }
          t=0;t1=0;
          for(int k=0;k<l;k++)
          {
             t=yn[k];
             if(t!=0)
                len++;
            }
            for(int k1=0;k1<l1;k1++)
            {
              t1=pn[k1];
              if(t1!=0)
                 len1++;
            }
             nl=len+len1;
            for(i=1;i<=6;i++)
            {
                nl1=nl;
              while(nl1>=1)
              {
                 if(p>(sz-1))
                 {
                    p=0;
                    p++;
                 }
                 else
                 p++;
                nl1--;
              }
              p--;
            for(k=p+1;k<=(sz-1);k++)
                a[k-1]=a[k];
                sz--;
            }
            printf("\n");
            printf("YOUR RELATION WID UR PARTNER IS:");
            printf("\n");
            if(a[sz]=='f')
            printf("you and your partner are friends");
            else if(a[sz]=='l')
            printf(" you love your partner");
            else if(a[sz]=='a')
            printf("you adore ur partner");
            else if(a[sz]=='m')
            printf("you will marry your partner");
            else if(a[sz]=='e')
            printf("there is a relation of enemity");
            else if(a[sz]=='s')
            printf("your partner is ur sister");
            getch();
     }
     
    Last edited by a moderator: Sep 5, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    If you're going to post "demo/example" code then please observe the following:


    1. Use sensible variable names, not a, k, p, n11. This is so the code can be easily understood by others. Obviously YOU know what a,k,p etc mean but it's not so obvious for the rest of us.


    2. Write sensible comments throughout the code. This is so that someone reading the code can work out what each section of code is doing.

    Here's an example of a pointless comment:
    Code:
    i++; // increment i
    
    We know i++ increments i; this doesn't need commenting. The "increment i" comment adds nothing to the reader's understanding. Here's an example of a good comment:
    Code:
    // Calculate the average (avg) of the stats array
    int total=0, avg=0;
    for (int i=0; i<STATS_SIZE; i++)
    {
      total+=stats[i];
    }
    avg=total/STATS_SIZE;
    

    3. Use correct formatting. The following is WRONG because it implies sz--; is part of the loop:
    Code:
            for(k=p+1;k<=(sz-1);k++)
                a[k-1]=a[k];
                sz--;
    
    and this should of course be:
    Code:
            for(k=p+1;k<=(sz-1);k++)
            {
                a[k-1]=a[k];
            }
            sz--;
    
    This also places braces on a line by themselves. Remember what you're trying to do here is to communicate clear program code, not to win any prizes for terseness and compactness, and this means spreading stuff out a bit. Please don't interpret that as "you have to double space everything", because too much space can make stuff just as hard to read as too little.

    4. In your comments please use correct English. So the following is WRONG because it uses txtspeak:

    so just enter ur first name
    n den ur partner's name
    and see the result

    Look, writing "your" instead of "ur" is only two more letters. Further, you have a QWERTY keyboard presumably and aren't typing this lot in on a mobile phone. Better:

    So enter your first name and your partner's first name, then the result will be displayed.

    The idea is that the reader will be able to understand what you're saying without having to decode it first. If they have to try to work out what you're prattling on about then this introduces ambiguity that makes it harder to understand.


    5. Be aware of letters that look like numbers. What's j counting up to: eleven, or LL, or L-one, or something else?
    Code:
    for(j=0;j<l1;j++)
    
    But with sensible names this isn't too problematical:
    Code:
    for(j=0;j<partner_length;j++)
    
     

Share This Page