On a previous question:  "Write a C code that creates an honor list for the top six students at SMC.  Your program does this by asking the user to enter the full names of all the top students, their majors, and their GPAs.  Your program then prints the listing of the students in a sorted fashion based on their GPAs, in a three-column format (Name, Major, and GPA). "   I received the below code, but I received errors when ran. Attached is a screenshot of the errors.    Is there something I should change?     #include #include int main() {     int i,n=10,a,j;     char NAME[n][30],MAJOR[n][30],str[10];     float GPA[n];    //execute for loop from 0 to number of top student     for(i=0; iGPA[j+1]             if(GPA[j]

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter4: Financial Functions, Data Tables, And Amortization Schedules
Section: Chapter Questions
Problem 8AYK
icon
Related questions
Topic Video
Question

On a previous question: 

"Write a C code that creates an honor list for the top six students at SMC.  Your program does this by asking the user to enter the full names of all the top students, their majors, and their GPAs.  Your program then prints the listing of the students in a sorted fashion based on their GPAs, in a three-column format (Name, Major, and GPA). "

 

I received the below code, but I received errors when ran. Attached is a screenshot of the errors. 

 

Is there something I should change?

 

 

#include <stdio.h>
#include <string.h>

int main()
{
    int i,n=10,a,j;
    char NAME[n][30],MAJOR[n][30],str[10];
    float GPA[n];
   //execute for loop from 0 to number of top student
    for(i=0; i<n; i++)
    {
        //input student NAME
        printf("Enter student NAME:");
        scanf("%d",&a);
        scanf("%[^\n]%*c",NAME[i]);

        //input MAJOR name
        printf("Enter MAJOR:");
        scanf("%[^\n]%*c",MAJOR[i]);
        //take GPA from user
        printf("Enter GPA:");
        scanf("%f",&GPA[i]);

    }
    //sort data in descending order based on GPA
    //so first 6 student are top 6 students
    for(i=0; i<n-1; i++)
    {
        for(j=0; j<n-i-1; j++)
        {
           //if you want to sort data in ascending order then use GPA[j]>GPA[j+1]
            if(GPA[j]<GPA[j+1])
            {
               //swap GPA
                float tmp=GPA[j];
                GPA[j]=GPA[j+1];
                GPA[j+1]=tmp;
              //swap NAME
                char s[30];
                strcpy(s,NAME[j]);
                strcpy(NAME[j],NAME[j+1]);
                strcpy(NAME[j+1],s);
              //swap MAJOR
                char s1[30];
                strcpy(s1,MAJOR[j]);
                strcpy(MAJOR[j],MAJOR[j+1]);
                strcpy(MAJOR[j+1],s1);
            }
        }
    }
    char sNAME[30]="Name";
    char sMAJOR[20]="Major";
    char sGPA[10]="GPA";
   //print formated output after sorting
    printf("\n%-30s %20s %10s\n",sNAME,sMAJOR,sGPA);
    for(i=0; i<n; i++)
    {
        printf("%-30s %20s %10.2f\n",NAME[i],MAJOR[i],GPA[i]);
    }
    return 0;
}

Error List
Entire Solution
X 22 Errors
A o Warnings
O O Messages
Build + IntelliSense
Search Error List
Code
Description
Project
File
Line Suppression State
String HW
String_HW
String HW
abt E0028
expression must have a constant value
Source.c
8
Aar E0028
expression must have a constant value
Source.c
8
abr E0028
expression must have a constant value
Source.c
9
* C2057 expected constant expression
O C2466
String_HW
Source.c
8
cannot allocate an array of constant size 0
String_HW
Source.c
8
* C2133
'NAME': unknown size
String_HW
Source.c
8
* C2057
O C2466
X C2133
expected constant expression
String_HW
Source.c
8
String_HW
String_HW
cannot allocate an array of constant size 0
Source.c
8
'MAJOR': unknown size
Source.c
8
X) C2057
expected constant expression
String_HW
Source.c
9
* C2466
cannot allocate an array of constant size 0
String_HW
Source.c
9
* C2133
"GPA': unknown size
String_HW
Source.c
9
'scanf': This function or variable may be unsafe. Consider using scanfs instead. To disable
deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
'scanf': This function or variable may be unsafe. Consider using scanfs instead. To disable A
deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
* C4996
String_HW
Source.c
15
X C4996
Source.c
16
'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable
deprecation, use CRT_SECURE_NO WARNINGS. See online help for details.
'scanf': This function or variable may be unsafe. Consider using scanf s instead. To disable
deprecation, use_CRT_SECURE_NO WARNINGS. See online help for details.
* C4996
String_HW
Source.c
20
X C4996
String_HW
Source.c
23
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To
disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To
disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
O C4996
String_HW
Source.c
41
O C4996
String_HW
Source.c
42
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To
disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
X C4996
String_HW
Source.c
43
* C4996
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To
disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
String_HW
Source.c
46
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To
disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
* C4996
String_HW
Source.c
47
X C4996
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To
disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
String_HW
Source.c
48
Transcribed Image Text:Error List Entire Solution X 22 Errors A o Warnings O O Messages Build + IntelliSense Search Error List Code Description Project File Line Suppression State String HW String_HW String HW abt E0028 expression must have a constant value Source.c 8 Aar E0028 expression must have a constant value Source.c 8 abr E0028 expression must have a constant value Source.c 9 * C2057 expected constant expression O C2466 String_HW Source.c 8 cannot allocate an array of constant size 0 String_HW Source.c 8 * C2133 'NAME': unknown size String_HW Source.c 8 * C2057 O C2466 X C2133 expected constant expression String_HW Source.c 8 String_HW String_HW cannot allocate an array of constant size 0 Source.c 8 'MAJOR': unknown size Source.c 8 X) C2057 expected constant expression String_HW Source.c 9 * C2466 cannot allocate an array of constant size 0 String_HW Source.c 9 * C2133 "GPA': unknown size String_HW Source.c 9 'scanf': This function or variable may be unsafe. Consider using scanfs instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. 'scanf': This function or variable may be unsafe. Consider using scanfs instead. To disable A deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. * C4996 String_HW Source.c 15 X C4996 Source.c 16 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use CRT_SECURE_NO WARNINGS. See online help for details. 'scanf': This function or variable may be unsafe. Consider using scanf s instead. To disable deprecation, use_CRT_SECURE_NO WARNINGS. See online help for details. * C4996 String_HW Source.c 20 X C4996 String_HW Source.c 23 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. O C4996 String_HW Source.c 41 O C4996 String_HW Source.c 42 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. X C4996 String_HW Source.c 43 * C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. String_HW Source.c 46 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. * C4996 String_HW Source.c 47 X C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. String_HW Source.c 48
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 6 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning