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

structures in C

Discussion in 'C' started by huhz, Nov 27, 2010.

  1. huhz

    huhz New Member

    Joined:
    Nov 27, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello, I had a task to write a code for given task. I wrote it and everything was okey, but now I have to rewrite that same code with the help of structures and I have some problems doing that and I really can't figure out that, because I don't have a big experience in C and materials which I have doesn't help a lot. So, I am going to add code of the first task which worked as planed:
    Code:
    # include <stdio.h>
    # include <ctype.h>
    # include <conio.h>  
    
    float A, formul1, formul2;
    
    int main() 
    {
    int Ae = 0;
                             
      printf("Enter exam mark: ");
      scanf("%d", &Ae);   
      getchar();
             while ( Ae < 1 || Ae > 10 ) 
    {     
             printf("Enter a number(border from 1 to 10):");   
             scanf("%d", &Ae);  
             getchar();
    };
    printf("Data correct: %d\n", Ae);
    
    int Alab = 0;
                             
      printf("Enter laboratory work mark: ");
      scanf("%d", &Alab);   
      getchar();
             while ( Alab < 1 || Alab > 10 ) 
    {     
             printf("Enter a number(border from 1 to 10):");   
             scanf("%d", &Alab);  
            getchar();
    };
    printf("Data correct: %d\n", Alab);
      
    int Aref = 0;
                             
      printf("Enter report mark: ");
      scanf("%d", &Aref);   
      getchar();
             while ( Aref < 1 || Aref > 10 ) 
    {     
             printf("Enter a number(border from 1 to 10):");   
             scanf("%d", &Aref);  
             getchar();
    };
    printf("Data correct: %d\n", Aref);
      
    formul1 =( ( 0.6*Ae ) + ( 0.3*Alab ) + ( 0.1*Aref ) );
    formul2 = Ae;
    if ( Ae >= 4 ) A = formul1; else A = formul2;
      
      printf("%2.1f - Exam mark\n",A);
      getche();
      return 0;
    }
    
    So I started to rewrite this code and did some of the work, but then I got some problems and now i can't finish this work because of those problems. So I am going to add my code(not finished) for second work:
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <windows.h>
    #define N 25
    
    int menu();
    
    int main()
    {
    
    struct list
       {
          int nr;
          char name[20], surname[20], exam_mrk[2], laboratory_mrk[2], report_mrk[2];
          float mrk;
       } student[N];
    int i,j,x;
    
    
    while (x != 4)
     { 
    x = menu();
    
    switch(x){
              case 1: printf("blablabla");             
                      getch();
                      system("cls"); 
                      break; 
                   
              case 2: printf("Save information about students which includes: ");
                      printf("Student name, surname, marks, final mark");
                      printf("(according to the first code)");
                      printf ("provide opportunity to list all unsuccessful students ");
                      getch();
                      system("cls");
                      break; 
                      
              case 3: printf("Fill the list please\n");
                      for(i=0; i<N; i++)
                      {
                               student[i].nr = i+1;
                               printf("\nEnter %d. student information\n", i+1);
                               printf("Name: ");
                               gets(student[i].name);
                               printf("Surname: ");
                               gets(student[i].Surname);
                               printf("Exam mark: ");
                               gets(student[i].exam_mrk);
                               printf("Laboratory work mark: ");
                               gets(student[i].laboratory_mrk);
                               printf("Report mark: ");
                               gets(student[i].report_mrk);
                                                              
                                                                       
    
               system("cls");
               printf("List of students\n");
               for(i=0; i<N; i++)
               printf("%2d%15s%15s%2d%2d%2d%4.2f\n", student[i].nr, student[i].name, student[i].surname, student[i].exam_mrk, student[i].laboratory_mrk, student[i].report_mrk, student[i].mrk);
               
               
               getch();
               return 0;
                         
              case 4: for(i=0; i<N; i++)
                      {
                      if((student[i].mrk)<4)
                          printf("%2d%15s%15s%2d%2d%2d%4.2f\n", student[i].nr, student[i].name, student[i].surname, student[i].exam_mrk, student[i].laboratory_mrk, student[i].report_mrk, student[i].mrk);  
                      }
              getch();
              system("cls"); 
              break; 
              
              case 5:
              return 0;
              break;
              
              default:
              printf("You entered wrong symbol");
              break;
                    
                    printf("\n Any key to continue !! \n");
                    getch();
                    system("cls");
      
       }              
      }
     }
    }
    
    int menu() 
         {
         int q;                  
         printf("Menu\n");
         printf("Choose operation:\n");
         printf("1.Info about creator\n");
         printf("2.Task terms\n");
         printf("3.Start program\n");
         printf("4.List all unsuccessful students\n");    
         printf("5.Quit\n\n");   
         scanf("%d",&q);
         return q;
         }
    
    So, I have following problems:
    1. I can't figure out how to rewrite function from 1. task which calculates final mark in the second work(how to rewrite this - formul1 =( ( 0.6*Ae ) + ( 0.3*Alab ) + ( 0.1*Aref ) );
    formul2 = Ae;
    if ( Ae >= 4 ) A = formul1; else A = formul2;)
    2. And the second problem is, i don't know rewrite code, to set restriction for entered symbols, that is, restrictions for numbers only
    I would be very thankful if someone could help me with this, because without of these 2 things I can't finish my work, and the problem is that I can't figure these 2 problems out.
     
  2. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Can you share what you are trying with structures because looking at the code and understanding what you are trying is bit tedious at time.
     
  3. huhz

    huhz New Member

    Joined:
    Nov 27, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    My main goal is to write program in structures, which saves information about student: name,surname, exam mark, laboratory work mark, report mark, and also final mark which is calculated by formal. is this program I need to put in formula which calculates final mark and then puts it in list( formula like in 1. code) and 2. thing is, that i need to set restrictions for entering numbers only
     
  4. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Looks pretty simple and have you tried anything in this line.
     
  5. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    if it looks so simple then why are not trying out urself coderzone…? this time he is not putting any homework on our shoulder..please help him out with ur code…I am eager to see ur code at least once…
     
  6. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Why you are so interested in seeing my code. Read this and you will not be interested in my code any more.
     
  7. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    I have already read that...you are an expert thatz why i want to see ur code...
     
  8. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Your assumption is not very right.
     
  9. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    I am always rite...
     
  10. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Good to see your confidence.
     
  11. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    Why will not be confident ? You dnt know me...I can show u the level of expertise...
     
  12. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    I see your expertise level on your site buddy. I can sense your bookish knowledge. Looks like you are a good teacher.
     
  13. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    Hmmm...at least I can teach...LOLzz
     
  14. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Did I say no.
     
  15. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    No..U did not understand...I said at least i can do that..but not u
     

Share This Page