Thread: warning: assignment makes integer from pointer without a cast

  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    Philadelphia, PA
    Posts
    27

    warning: assignment makes integer from pointer without a cast

    Hello, hopefully someone will be able to help me.

    "warning: assignment makes integer from pointer without a cast" is the error i get when i try to compile simple program that converts numer score into letter grade. What am I doing
    wrong?

    Thanks in advance,
    Andriy

    This is the code:

    Code:
    #include <stdio.h>
    
    int
    main(void)
    
    {
            char grade;
            int get_score, num_score;
    
            /*get users input */
    
            printf("Type in the numeric grade and press return> ");
            scanf("%lf", &num_score);
    
            /*converts the numeric score to letter grade*/
    
            if(num_score > 89)
               grade = "A";
            else if(num_score > 79)
               grade = "B";
            else if(num_score > 69)
               grade = "C";
            else if(num_score > 59)
               grade = "D";
            else if(num_score < 58)
               grade = "F";
    
            /*prints out the letter grade */
    
            printf("Your score of %lf is a %c grade.\n",
                     num_score, grade);
    
            return(0);
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> grade = "A";

    double quotes are for string literals - use single quotes.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Feb 2006
    Location
    Philadelphia, PA
    Posts
    27
    thanks for the quick reply. Now my program compiles, but when i enter a number grade, my output is:

    Code:
    Type in the numeric grade and press return> 70
    Your score of 0.000000 is a R grade.
    Any idea why this is happening? I can't really see anything wrong with my code (but I just started learning). Strange.
    Last edited by ademkiv; 02-12-2006 at 07:57 PM.

  4. #4
    Drunken Progammer CaptainMorgan's Avatar
    Join Date
    Feb 2006
    Location
    On The Rocks
    Posts
    45
    Quote Originally Posted by ademkiv
    thanks for the quick reply. Now my program compiles, but when i enter a number grade, my output is:

    Code:
    Type in the numeric grade and press return> 70
    Your score of 0.000000 is a R grade.
    Any idea why this is happening? I can't really see anything wrong with my code (but I just started learning). Strange.
    You need to read up on format specifiers.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Location
    Philadelphia, PA
    Posts
    27
    looks like i'm screwed. I have to write this program using functions, but at first i was trying to write it the simplest way possible and then modify it to use functions. It looks like I can't even do the simple part.

  6. #6
    Registered User dinjas's Avatar
    Join Date
    Feb 2005
    Location
    Vancouver, Washington
    Posts
    40
    man, dont give up so easy... use his suggestion and roll with it, perhaps to google?
    and maybe do a search for something like ... hmm

    C format specifiers

    or maybe you should just store your scores in double's instead of int's
    straight off the heap

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    Code:
    #include <stdio.h>
    
    int
    main(void)
    
    {
            char grade;
           double num_score;
    
            /*get users input */
    
            printf("Type in the numeric grade and press return> ");
            scanf("%lf", &num_score);
    
            /*converts the numeric score to letter grade*/
    
            if(num_score > 89)
               grade = 'A';
            else if(num_score > 79)
               grade = 'B';
            else if(num_score > 69)
               grade = 'C';
            else if(num_score > 59)
               grade = 'D';
            else if(num_score < 58)
               grade = 'F';
    
            /*prints out the letter grade */
    
            printf("Your score of %f is a %c grade.\n",
                     num_score, grade);
    
            return(0);
    }


    ok here is the code,i have made the changes,just use copy and paste (no need to type the changes again. )
    want this done in function style,just ask.
    anystyle u want.
    dont worry,i am here to do all your homework for u FOR FREE.




    __________________________________________________ __
    Last edited by qqqqxxxx; 02-13-2006 at 05:36 AM.

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    43
    You also might want to reconsider those if statements. For example, what if the user got a between a 58 and a 59 for a grade? Try typing that into the input and see what it prints for a letter grade, then see if you can find the problem.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Just a simple else will do at the end because the score can be nothing else.

    Code:
            else if(num_score > 59)
               grade = 'D';
            else
               grade = 'F';

  10. #10
    Registered User
    Join Date
    Feb 2006
    Location
    Philadelphia, PA
    Posts
    27
    qqqqxxxx, thank you, it works now! As for my homework, i'm going do it myself because i want to learn something. If I will have problems then I will ask.

    I have a lab today where I will need to convert this program to use functions. Hopefully everything will go smooth.

    Thank you to everyone who tried to help.

  11. #11
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    YAY! Exactly the kind of attidude we want to see among newcomers!

    As for qqqqxxxx; You are in no way at all helping a person by doing their whole homework! They dont learn anything, they might come here and expect us to do all the homework for them in the future, and in worst case, they will fail! Simply dont do all the work for them!
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  12. #12
    Registered User
    Join Date
    Feb 2006
    Location
    Philadelphia, PA
    Posts
    27

    with functions

    Hello again,

    Here's my 1st attempt to convert that program to use functions with some added functionality.

    Code:
    #include <stdio.h>
            
    /* Prompts user to enter the score */
    
    int getScore(int numScore);
    
    /*Converts a numberic score to a letter grade */
    
    char convertGrade(int numScore);
            
    /*Displays the original numeric score, the corresponding letter grade
     *if the score is valid, and an appropriate eror message if the score
     *if the score is not valid 
     */
              
    void showGrade(int numScore, char letterGrade);  
              
    int 
    main(void);
    {
            
            char    letterGrade, printGrade, showGrade, convertGrade;
            int     numScore;
    
            getScore(numScore);
    
            letterGrade = convertGrade(numScore);
            
            printGrade = showGrade(numScore);
            
            return(showGrade);  
    }
           /*Fuction that prompts user to enter the score */
              
    int getScore(int numScore);
    {
            printf("Please enter numeric grade  and press return>");
            scanf("%d", &numScore);
    }
            
    /*Function converts a numeric score to a letter grade */
            
    char convertGrade (int numScore, char letterGrade);
    {
            if(numScore >= 90)
              letterGrade = 'A';
            else if(numScore >= 80)
              letterGrade = 'B';
            else if(numScore >= 70)
              letterGrade = 'C';
            else if(numScore >= 60)
              letterGrade = 'D';
            else if(numScore <= 59)
              letterGrade = 'F';
            else if(numScore > 100 && numScore < 0)
              letterGrade = 'Z';   
    }
            
    /*Function prints out the letter grade */
    {       
    void showGrade(int numScore, char letterGrade);
     
            if(letterGrade='Z')
            printf("\nYour score of %f is not valid.\n", letterGrade);
            else 
            printf("\nYour score of %f is a %c grade.\n", numScore, letterGrade);
            
    }
    When I try to compile the code, i get the following errors.

    Code:
    grade_calc.c:19: error: syntax error before '{' token
    grade_calc.c:24: warning: parameter names (without types) in function declaration
    grade_calc.c:24: warning: data definition has no type or storage class
    grade_calc.c:26: error: initializer element is not constant
    grade_calc.c:26: warning: data definition has no type or storage class
    grade_calc.c:28: error: too few arguments to function `showGrade'
    grade_calc.c:28: error: void value not ignored as it ought to be
    grade_calc.c:28: error: initializer element is not constant
    grade_calc.c:28: warning: data definition has no type or storage class
    grade_calc.c:30: error: syntax error before "return"
    grade_calc.c:36: error: syntax error before '{' token
    grade_calc.c:38: error: syntax error before string constant
    grade_calc.c:38: error: conflicting types for 'scanf'
    grade_calc.c:38: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
    grade_calc.c:38: error: conflicting types for 'scanf'
    grade_calc.c:38: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
    grade_calc.c:38: warning: data definition has no type or storage class
    grade_calc.c:43: error: conflicting types for 'convertGrade'
    grade_calc.c:8: error: previous declaration of 'convertGrade' was here
    grade_calc.c:43: error: conflicting types for 'convertGrade'
    grade_calc.c:8: error: previous declaration of 'convertGrade' was here
    grade_calc.c:44: error: syntax error before '{' token
    Any suggestions??

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > main(void);
    Function declarations don't have ; at the end (all 3 of them)

    You're mixing them with function prototypes (which do end with a ; )

  14. #14
    Registered User
    Join Date
    Feb 2006
    Location
    Philadelphia, PA
    Posts
    27
    Quote Originally Posted by Salem
    > main(void);
    Function declarations don't have ; at the end (all 3 of them)

    You're mixing them with function prototypes (which do end with a ; )
    Thanks, I made the changes and now I get a few errors when compiling:
    Code:
    grade_calc.c: In function `main':
    grade_calc.c:26: error: called object is not a function
    grade_calc.c:28: error: called object is not a function
    grade_calc.c: At top level:
    grade_calc.c:44: error: conflicting types for 'convertGrade'
    grade_calc.c:8: error: previous declaration of 'convertGrade' was here
    grade_calc.c:44: error: conflicting types for 'convertGrade'
    grade_calc.c:8: error: previous declaration of 'convertGrade' was here
    grade_calc.c:60: error: syntax error before '{' token

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > grade_calc.c:26: error: called object is not a function
    > printGrade = showGrade(numScore);
    You have a local variable with the same name as a function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM