My Program Won't Display First Few Data...

This is a discussion on My Program Won't Display First Few Data... within the C Programming forums, part of the General Programming Boards category; hey guys, can you please help me out with my project? i made a program that would ask the user ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    1

    My Program Won't Display First Few Data...

    hey guys, can you please help me out with my project? i made a program that would ask the user to input names, which the program would then arrange alphabetically. Then the program would ask for quiz grades, project grade, and final examination grade. The program then would compute for the raw score and display the corresponding mark (4.0 = 95 to 100, 3.5 = 90 - 95, etc.)

    The problem is that, my program displays the grades properly, but the first few names aren't displayed. i don't see anything wrong with my program but i'm sure there is. Please do reply to my post! any help would be appreciated.


    Code:
    #include<iostream.h>
    #include<stdio.h>
    #include<iomanip.h>
    
    struct records
    {
    float quiz_1;
    float quiz_2;
    float quiz_3;
    float proj;
    float finals;
    float raw;
    float final_grade;
    };
    
    main()
    {
    FILE *fp;
    fp=fopen("C:\\Users\\User\\Documents\\ClassDataBase.txt","w");
    {
    records *rec;
    char *name[50], temp[50];
    int m, n, x;
    rec=new records[x];
    
    printf("@@@@@\t@@@@@\t@@@@@@@@@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@@@@@@@@@\n@@@@@\t@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@@@@@@@@@\t@@@@@@@@@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@\t@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@\t@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@\t@@@@@\t@@@@@@@@@@@@@\t@@@@@@@@@@@@@\t@@@@@@@@@@@@@\t@@@@@@@@@@@@@\n\n");
    fprintf(fp,"@@@@@\t@@@@@\t@@@@@@@@@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@@@@@@@@@\n@@@@@\t@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@@@@@@@@@\t@@@@@@@@@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@\t@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@\t@@@@@\t@@@@@\t\t@@@@@\t\t@@@@@\t\t@@@@@\t@@@@@\n@@@@@\t@@@@@\t@@@@@@@@@@@@@\t@@@@@@@@@@@@@\t@@@@@@@@@@@@@\t@@@@@@@@@@@@@\n\n");
    printf("How many records would you like to enter?");
    scanf("%d",&x);
    for (m=0;m<x;m++)
    {
    printf("\nEnter name: ");
    name[m] = (char *) malloc (50);
    scanf("%s",name[m]);
    }
     for (m = 0; m <= x; m++)
    {
    for (n = 1; n <= x-m; n++)
    if (strcmp(name[n - 1], name[n]) > 0)
    {
    strcpy(temp, name[n - 1]);
    strcpy(name[n - 1], name[n]);
    strcpy(name[n], temp);
    temp[0] = '\0';
    }
    }
    
     for(m=0;m<x;m++)
     { 
       printf("\n\nInput Grades For %s\n",name[m]);
       printf("   Quiz 1: ");
       scanf("%f",&rec[m].quiz_1);
       printf("   Quiz 2: ");
       scanf("%f",&rec[m].quiz_2);
       printf("   Quiz 3: ");
       scanf("%f",&rec[m].quiz_3);
       printf("   Project: ");
       scanf("%f",&rec[m].proj);
       printf("   Finals: ");
       scanf("%f",&rec[m].finals);
       rec[m].raw=((((rec[m].quiz_1)+(rec[m].quiz_2)+(rec[m].quiz_3))/3)*0.40)+((rec[m].proj)*0.20)+((rec[m].finals)*0.40);
     
     if(rec[m].raw<60)
     {
     rec[m].final_grade=0;
     }
     if(rec[m].raw>=60&&rec[m].raw<65)
     {
     rec[m].final_grade=1;
     }
     if(rec[m].raw>=65&&rec[m].raw<70)
     {
     rec[m].final_grade=1.5;
     }
     if(rec[m].raw>=70&&rec[m].raw<75)
     {
     rec[m].final_grade=2.0;
    }
    if(rec[m].raw>=75&&rec[m].raw<85)
     {
     rec[m].final_grade=2.5;
    }
    if(rec[m].raw>=85&&rec[m].raw<90)
     {
     rec[m].final_grade=3.0;
    }
    if(rec[m].raw>=90&&rec[m].raw<95)
     {
     rec[m].final_grade=3.5;
    }
    if(rec[m].raw>=95)
     {
     rec[m].final_grade=4.0;
    }
    }
    
    
    printf("----------RECORDS----------\n\n");
    fprintf(fp,"----------RECORDS----------\n\n");
    printf("Name\t\tQuiz 1\tQuiz 2\tQuiz 3\tProject\tFinals\tRaw\tFinal Grade\n"); 
    fprintf(fp,"Name\t\tQuiz 1\tQuiz 2\tQuiz 3\tProject\tFinals\tRaw\tFinal Grade\n"); 
     for (m=0; m<x; m++)
    {
    printf("%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n\n", name[m],rec[m].quiz_1,rec[m].quiz_2,rec[m].quiz_3,rec[m].proj,rec[m].finals,rec[m].raw,rec[m].final_grade);
    fprintf(fp,"%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n\n", name[m],rec[m].quiz_1,rec[m].quiz_2,rec[m].quiz_3,rec[m].proj,rec[m].finals,rec[m].raw,rec[m].final_grade);
    }
    fclose(fp);
    system("pause");
    }
    }
    Output should be something like this:

    ----------RECORDS----------

    Name Quiz 1 Quiz 2 Quiz 3 Project Finals Raw Final Grade
    Lee,Bruce.K. 96.00 94.00 95.00 96.00 94.00 94.80 3.50

    Smith,John.C. 95.00 99.00 994.00 94.00 99.00 216.80 4.00

    Tan,Mike.J. 59.00 96.00 95.00 94.00 89.00 87.73 3.00


    Instead, it shows*:

    ----------RECORDS----------

    Name Quiz 1 Quiz 2 Quiz 3 Project Finals Raw Final Grade
    96.00 94.00 95.00 96.00 94.00 94.80 3.50

    Smith,John.C. 95.00 99.00 994.00 94.00 99.00 216.80 4.00

    Tan,Mike.J. 59.00 96.00 95.00 94.00 89.00 87.73 3.00

    *not displaying Lee,Bruce.K.

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    960
    Not sure how it even runs.

    Code:
    int m, n, x;
    rec=new records[x];

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Are you trying to write C or C++? Because that's a lot of C++. You're on the wrong forum.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program terminates abruptly
    By roaan in forum C Programming
    Replies: 3
    Last Post: 08-28-2009, 03:53 PM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  3. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  4. Replies: 26
    Last Post: 06-15-2005, 02:38 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21