tags:

views:

168

answers:

3

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;
}
+7  A: 

mrk is declared as a pointer to an int but you are not dereferencing it.

Replace

char assess(int* mrk) 

with

char assess(int mrk)

in the definition of assess

Similarly, you declared (prototyped) assess as

void assess(int* mrk)

Replace with

char assess(int mrk)

Next,

if(mrk >= 35 && <= 39)

is not legal syntax. I know it reads like mrk is greater than or equal to 35 and less than or equal to 39 but you have to be more explicit for the compiler. So

replace

if(mrk >= 35 && <= 39)

with

if(mrk >= 35 && mrk <= 39)

and similarly throughout.

Next, in assess you have declared result as a char but you are assigning char *s to result. Replace

result = "f";

with

result = 'f';

and similarly for all assignments to result. In particular

result = "error";

should be something like

result = 'z'; /* 'z' indicates failure */
Jason
Excellent, thank you.
Jamie Keeling
Tim Goodman
@Tim Goodman: Good elaboration; thanks!
Jason
Great, thankyou!
Jamie Keeling
+2  A: 

Your function prototype is void and the implementation is char as a return type. Also you're passing a parameter as a pointer....you should not use a pointer to pass ints unless you want to change the int that was passed in. Passing pointers for ints isn't a speedup since you end up passing a pointer that is the same size as an int anyway.

Chris H
I've upvoted the answer, i can't believe i missed this. Thank you.
Jamie Keeling
+1  A: 
tommieb75