C program about transfering character to number

The result of this program is

show 6 of the character that i input
and transfer it into number
and finally sum of the numbers

what should be show:
Please input Result 1 -> A
Please input Result 2 -> B
Please input Result 3 -> C
Please input Result 4 -> D
Please input Result 5 -> E
Please input Result 6 -> F

Result 1 -> A -> 5
Result 2 -> B -> 4
Result 3 -> C -> 3
Result 4 -> D -> 2
Result 5 -> E -> 1
Result 6 -> F -> 0

after transformation, the total point obtained is 15.


Write your question here.

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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


int toPoint(char r){
        int thePoint;

        r=toupper(r);

        switch(r){
        case 'A':
        thePoint = 5;
        break;
        case 'B':
        thePoint = 4;
        break;
        case 'C':
        thePoint = 3;
        break;
        case 'D':
        thePoint = 2;
        break;
        case 'E':
        thePoint = 1;
        break;
        case 'F':
        thePoint = 0;
        break;



        }
        return thePoint;
}


int main(){
        int total = 0;
        int i;
        int k;
        int x;
        char *grade;

        grade =(char *) malloc(6* sizeof(char));

        for(i=0; i<=5; i++){
            printf("Please input Result %d -> ", i+1);
            scanf(" %c", grade +i);
            printf("\n");
        }

        for (k=0; k<=5; k++){

// what do you mean set up to pass pointer?   i have placed char r for passing the value 
//is it work?     
//and i wanted to add the points up, so i do  x++,  is it some other way better?  
              x = toPoint(grade);

            printf("Result %d -> %c -> %d", k+1, grade, x+k);
            printf("\n");
                 total = x++;
                      


        }
          
      printf("After transformation, the total point obtained is %d", total);

}


I don't know why i can never transform the character, and of course cant get the total.

I tried many other things, still dont have any clues.

Last edited on
On line 54 you are passing a pointer to a function that isn't set up to handle that. On line 63 I know my compiler would complain about Printf with the capital 'P'. In your toPoint function you have all cases returning an int 5.


sorry the switch was wrong version.
Topic archived. No new replies allowed.