Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Simple error on C programming (http://www.go4expert.com/forums/simple-error-c-programming-t2419/)

PEANUTS 2Jan2007 20:10

Simple error on C programming
 
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 Code:

/* 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);
        }
/////////////////////////////////////////////////////////////


DaWei 2Jan2007 20:28

Re: Simple error on C programming
 
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.


All times are GMT +5.5. The time now is 22:23.