1. need sum help with a function please!!

OK, i am very new to programming as a whole infact i have only been doing it for a couple of months i am generally getting on ok with it,altho frustrating at time but i am stuck on something that i have to do for college. I have written a program that calculates two exam results and gives out a total mark and converts the total marks to a grade from A - F, however i have not put it into fuctions. i have tried and tried to separate my programme into functions but i cant seem to get it to work can anybody give me some assistance.

Code:
```#include <stdio.h>
#include <conio.h>
int main(void)
{
int examMark;
int assignMark;
int totalMark;

{
printf("\nEnter exam mark out of 50: ");
scanf("%d", &examMark);
printf("\nEnter assignment mark out of 50: ");
scanf("%d", &assignMark);

totalMark = examMark + assignMark;
if (totalMark >= 39)
{
if ((examMark <15) || (assignMark < 15))
{
totalMark = 39;
}
else
{
if (totalMark == 39)
{
totalMark = 40;
}
}
}
if (totalMark >=70)
{
}
else
{
if (totalMark >=60)
{
}
else
{
if (totalMark >= 50)
{
}
else
{
if (totalMark >= 40)
{
}
else
{
}
}
}
}
printf("\nExam : %d/50  Assignment : %d/50  Grade : %c\n\n", examMark, assignMark, grade);

}

return 0;
}```
any help at all would be much appriciated, cheers james

2. Well you basically look for blocks of code which seem to do a specific task.

So taking the bit of code which calculates the total...
Code:
```#include <stdio.h>
#include <conio.h>
int main(void)
{
int examMark;
int assignMark;
int totalMark;

{
printf("\nEnter exam mark out of 50: ");
scanf("%d", &examMark);
printf("\nEnter assignment mark out of 50: ");
scanf("%d", &assignMark);

totalMark = examMark + assignMark;
if (totalMark >= 39)
{
if ((examMark <15) || (assignMark < 15))
{
totalMark = 39;
}
else
{
if (totalMark == 39)
{
totalMark = 40;
}
}
}

if (totalMark >=70)
{
}
else
{
if (totalMark >=60)
{
}
else
{
if (totalMark >= 50)
{
}
else
{
if (totalMark >= 40)
{
}
else
{
}
}
}
}
printf("\nExam : %d/50  Assignment : %d/50  Grade : %c\n\n", examMark, assignMark, grade);

}

return 0;
}```
Would be something like this
Code:
```#include <stdio.h>
#include <conio.h>

int calculateTotal ( int examMark, int assignMark );

int main(void)
{
int examMark;
int assignMark;
int totalMark;

{
printf("\nEnter exam mark out of 50: ");
scanf("%d", &examMark);
printf("\nEnter assignment mark out of 50: ");
scanf("%d", &assignMark);

totalMark = calculateTotal( examMark, assignMark );

if (totalMark >=70)
{
}
else
{
if (totalMark >=60)
{
}
else
{
if (totalMark >= 50)
{
}
else
{
if (totalMark >= 40)
{
}
else
{
}
}
}
}
printf("\nExam : %d/50  Assignment : %d/50  Grade : %c\n\n", examMark, assignMark, grade);

}

return 0;
}

int calculateTotal ( int examMark, int assignMark ) {
int totalMark = examMark + assignMark;
if (totalMark >= 39)
{
if ((examMark <15) || (assignMark < 15))
{
totalMark = 39;
}
else
{
if (totalMark == 39)
{
totalMark = 40;
}
}
}
}
```

3. For example this part
Code:
```if (totalMark >=70)
{
}
else
{
if (totalMark >=60)
{
}
else
{
if (totalMark >= 50)
{
}
else
{
if (totalMark >= 40)
{
}
else
{
}
}
}
}```
can be easely converted to function
Code:
```char getGradeFromMark(int totalMark)
{
if (totalMark >=70)
{
return 'A';
}
if (totalMark >=60)
{
return 'B';
}
if (totalMark >= 50)
{
return 'C';
}
if (totalMark >= 40)
{
return 'D';
}
return 'F';
}```
Also you can create functions for entering scores, for calculating totalMark and for outputting resulting Grade

It took me too long

4. Heh - I guess he's got all he needs now that we've done one each

5. Thanx a lot i will go and give it a go and see if i can get it to work, much apprieciated, cheers again

james

6. Yeah it works like a charm....and wats more i actually understand what uve done which is always helpful for future programs cheers guys