Arrays and Structs

Hello all. Building a program that function is to convert a numeric score to a letter grade. I am getting an error at line 71 saying that xcode expects a statement. What type of statement is needed because I would of thought that the if statement at line 70 was just that.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma warning (disable:4996)
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define SIZE 5

/* Function prototypes
 */

// Function to prompt for and read a numeric score
// Returns an integer score as read in using scanf
int getScore();

// Function to convert a numeric score to a letter grade
// Returns the letter grade
char convertGrade(int numScore);
// IN: Student exam score

// Function to display a message for valid or invalid grade.
void showGrade(int numScore, char letterGrade);
// IN: Original student score
// IN: Corresponding letter grade





int main()
{
    int numScore;
    char letterGrade;
    
    
    while (numScore != 1000)
    {
        numScore = getScore();
        letterGrade = convertGrade(numScore);
        showGrade( numScore,  letterGrade);
        
        
        if (letterGrade == 'Z')
        {
            printf ("Terminating program\n");
        }
    }
    
}

int getScore()
{
    int numScore;
    printf("Welcome to the Score Converter.\n\n");
    printf("Please enter a numeric value.\n");
    printf("Press any key to exit:\n");
    scanf("%d", &numScore);
    return (numScore);
}

char convertGrade(int numScore)
{
    int i;
    static int minScores[SIZE]    // minimum scores for a grade range
    = {90, 80, 70, 60, 0};
    static int maxScores[SIZE]    // maximum scores for a grade range
    = {100, 89, 79, 69, 59};
    static char grades[SIZE]      // grade for the current grade range
    = {'A', 'B', 'C', 'D', 'F'};
    for (i=0; i<SIZE; i++)
    {
        if (numScore<=maxScores[i] && numScore>=minScores[i])
            }
    return grades[i];
}

void showGrade(int numScore, char letterGrade)
{
    if (letterGrade == 'Z')
    {
        printf ("Sorry. Score invalid.\n");
    }
    
    else
    {
        printf ("The score %d has received a letter grade of %c.\n", numScore, letterGrade);
    }
    
}
Last edited on
1
2
3
4
  for (i=0; i<SIZE; i++)
    {
        if (numScore<=maxScores[i] && numScore>=minScores[i])
            }


This doesnt do anything. Your if statement doesnt do anything.

If statements work like this. "If this, do that". And you have no "do that" part.

1
2
3
4
if (letterGrade == 'Z') // if this
    {
        printf ("Sorry. Score invalid.\n"); // do that
    }
But dont I still need a variation of lines 68 -73 to run the function?
You're using structs wrong. Thats not what structs do. You're creating an array, not sure why you have struct there aswell. Also, SIZE is undefined, Whats size? How big is size? You never say that.

https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83

Here's a playlist with a bunch of videos. Watch the ones on structs, arrays, if statements, anything you need basically :)
Oh I thought all I had to state was what I had on line 5.
oh whoopsie daysie... :D my bad. I never copy the top of the program when I try them out. Size is fine yes :D
Topic archived. No new replies allowed.