Thread: basic program help

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    basic program help

    i have create a program structure were i ask user for name and final grade and midterm. i want to add the final grade and midterm and get the average how do i add the values. do i need a structure to hold the value?? can someone help me please

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    
    
    struct student
    {
           char name[30];
           int final;
           int midterm;
    };
    struct number
    {
           int final;
           int midterm;
    };
    main()
    {
           struct student info[2];
           struct number adding[2];
           int i,total,final=0,h=0;
           for(i=0;i<2;i++)
           {
           printf("student %i\n",i+1);
           printf("Enter student name\n");
           scanf("%s",&info[i].name);
           printf("Enter final");
           scanf("%i",&info[i].final);
           printf("Enter midterm");
           scanf("%i",&info[i].midterm);
           }
           
           printf("name\tfinal \tmidtern\n"); 
          
           for(i=0;i<2;i++)
           {
          
           printf("\n%s \t%i \t%i\n",&info[i].name,info[i].final,info[i].midterm);
          // how do i add the values
            
            }
           
         
           
           getch();
    
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    It's just one equation you can do out of the loop. Just learn how to calculate an average, then write a function.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    i did it didnt work

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then show us what you did.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 29
    Last Post: 10-22-2009, 11:01 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. IDEA: A basic drawing program
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:15 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM