I am trying to write a very simple application that allows me to enter a number which will allocate a particular grade.
I’ve not used the C language very much as i primarily use C# however i still don’t seem to be able to get around the errors:
They are all syntax errors, ranging from “if” to “{” although i’m sure everything is as it should be.
One i don’t understand is the “void illegal with all types” at the grade = assess(mark);
section.
I understand the program may not product the correct output but im simply trying to get it to compile.
Thank you for your help, i imagine I’m doing something REALLY obvious.
Task.c
#include <stdio.h>
#include <string.h>
//Protoype
void assess(int* mrk);
// Main method (start point of program)
void main()
{
int mark;
char grade;
printf("enter a word: ");
scanf("%d", &mark);
grade = assess(mark);
printf("That equals ");
printf("%c", grade);
printf(" when marked\n");
}
char assess(int* mrk)
{
char result;
if(mrk > 0 && <= 100)
{
if(mrk < 35)
{
result = "f";
}
if(mrk >= 35 && <= 39)
{
result = "e";
}
if(mrk >= 40 && <= 49)
{
result = "d";
}
if(mrk >= 50 && <= 59)
{
result = "c";
}
if(mrk >= 60 && <= 69)
{
result = "b";
}
if(mrk > 70)
{
result = "a";
}
}
else
{
result = "error";
}
return result;
}
mrkis declared as a pointer to anintbut you are not dereferencing it.Replace
with
in the definition of
assessSimilarly, you declared (prototyped)
assessasReplace with
Next,
is not legal syntax. I know it reads like
mrkis greater than or equal to35and less than or equal to39but you have to be more explicit for the compiler. Soreplace
with
and similarly throughout.
Next, in
assessyou have declaredresultas acharbut you are assigningchar *s to result. Replacewith
and similarly for all assignments to
result. In particularshould be something like