Thread: what command to use??

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    19

    what command to use??

    The program below is working good. But now i need to change the input as
    enter no of student :
    enter no of subject :
    where the value is undefined 'x'. once i run the program it will ask for no of students and no of subject.when my input is
    10 automatically i want to have 10 student record and 10 subject...PLS HELP ON THIS...what statemement should i use..


    #include <stdio.h>



    int main()

    {

    int count = 0;

    char letter_grade = 'x';

    int a = 0, b = 0, c = 0, d = 0, e = 0;

    int student_ID = 1;

    double test1 = 0.0, test2 = 0.0, final_test = 0.0, semester_average = 0.0, class_average = 0.0;



    do

    {

    printf("Enter student ID, 0 to terminate: ");

    scanf("%d", &student_ID);



    if(student_ID != 0)

    {

    printf("Enter score #1: ");

    scanf("%lf", &test1);

    printf("Enter score #2: ");

    scanf("%lf", &test2);

    printf("Enter score #3: ");

    scanf("%lf", &final_test);



    printf("%d have the following scores: %lf, %lf and %lf\n", student_ID, test1, test2, final_test);

    semester_average = (0.20*test1) + (0.30*test2) + (0.50*final_test);

    printf("The semester average score for %d is %lf\n", student_ID, semester_average);

    if(semester_average >= 80)

    { letter_grade = 'A'; a++; }

    else if (semester_average >= 65)

    { letter_grade = 'B'; b++; }

    else if (semester_average >= 50)

    { letter_grade = 'C'; c++; }

    else if (semester_average >= 40)

    { letter_grade = 'D'; d++; }

    else if(semester_average >= 0)

    { letter_grade = 'E'; e++; }



    printf("The grade for %d is %c\n", student_ID, letter_grade);

    count++;

    printf("Student #: %d\n", count);

    }

    }while(student_ID != 0);



    printf("\nTotal number of student: %d\n", count);
    Last edited by scorpio76; 10-25-2010 at 01:03 AM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You can use a for loop to do it. Or a while loop. Or a do/while loop. Or goto. Or you can just ask for it 10 times... There's lots of ways!
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    And some ways are better than others.

    Don't use goto, even if it seems easier at the moment.

    In this case, you will most likely want to use a for loop.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    19
    this is the program code i need to change...

Popular pages Recent additions subscribe to a feed