1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Simple error on C programming

Discussion in 'C' started by PEANUTS, Jan 2, 2007.

  1. PEANUTS

    PEANUTS New Member

    Joined:
    Oct 13, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    The problem im having with my program is that. After i type the students name it, press return, its goes down not across to the next title. DOB and then to TEST1 etc.

    HTML:
    /* Header.c */
    #include <stdio.h>
    
    //////////////// Prototypes /////////////////////////////////////////////////////
    
    void OutputHeader();
    void Variable();
    void Student();
    
    
    //////////////////////// Global Variables //////////////////
    int EeCode;
    float StudentsName, DOB, Test1, Test2, Test3, Test4, Average, Grading, SumOfMarks, Exit;
    int Pass, Merit, Distinction, Fail, y=2;
    ///////////////////////////////////////////////////////////////////////////
    
    void main (void)
    {
    	 OutputHeader();
    	 Variable();
    	 gotoxy(1,y);
    	 scanf("%d",&EeCode);
    		while (EeCode !=0)
    		{
    			Student();
    			y++;
    			gotoxy(1,y);
    			scanf("%d", EeCode);
    		}
    
    
    
    
    
    
    
    
    
    getch();
    
    }
    
    ///////////////////////////////// My Functions ///////////////////////////////////
    
    void OutputHeader()
    	{
    	clrscr();
    	 gotoxy(1, 1);
    	printf("Students Name  D.O.B   Test 1  Test 2  Test 3  Test 4   Average  Grading");
    	}
    
    
    void Variable()
    	{
    	Pass=0;
    	Merit=0;
    	Distinction=0;
    	Fail=0;
    	}
    
    void Student()
    	{
    	gotoxy(16, y);
    	scanf("%f", &DOB);
    	gotoxy(24, y);
    	scanf("%f", &Test1);
    	gotoxy(32, y);
    	scanf("%f", &Test2);
    	gotoxy(40, y);
    	scanf("%f", &Test3);
    	gotoxy(48, y);
    	scanf("%f", &Test4);
    
    	 /* CalcAverageMark */
    	 SumOfMarks = Test1 +Test2 + Test3 + Test4;
    	 Average = SumOfMarks / 4;
      gotoxy(53, y);  printf("%6.0f\n", Average);
    	}
    /////////////////////////////////////////////////////////////
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Search through recent posts in this forum for the proper use of scanf. Hint: most people's names cannot be successfully converted to a floating point number.

    That said, aside from defining the name as a float, I don't see where you're actually asking for it. As an aside, I trust you realize that your use of screen-positioning functions is non-portable code.
     

Share This Page