#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Really simple program


    Hey,
    I am trying to make a really simple program that calculates your grade based on percentages that certain things are worth. im pretty much brand new to c programming and just trying to goof around with my own ideas inbetween class projects. heres my code

    Code:
    #include <stdio.h> 
     main(void)  
    { 
    float test;  // based on tests being worth 30% of grade 
    float final; // based on tests being worth 20% of grade 
    float labs;  // based on tests being worth 50% of grade 
    float grade;  
    
    printf("Please enter your average test grade\n"); 
    scanf("%f", &test);  
    
    printf("Please enter your final test grade\n"); 
    scanf("%f", &final);  
    
    printf("please enter your average lab grade\n"); 
    scanf("%f", labs);  
    
    grade = (test * .30) + (final * .20) + (labs * .50);  
    
    printf("your grade for this class is: %0.2f", grade);  
    return 0;  
    }
    and i get this error when compiling
    In function ‘main’:
    c-projects/personal/grade_calc.c:19:1: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double’ [-Wformat]

    so the error is with the %f thats supposed to be assigned to labs but im not really sure why thats an error.

    any help would be greatly appreciated, i know its probably something silly that im just not seeing but have been looking at this for over an hour now and cant put my finger on it.

    edit for error message because i was testing out %d instead of %f and posted the old message from test.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    found what was wrong, sorry to waste anyones time, was missing an & lol i knew it was a stupid mistake just had to take my eyes off it for a min to see
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0
    Code:
    scanf("%f", labs);
    you should give & to labs i.e scanf("%f", &labs);

IMN logo majestic logo threadwatch logo seochat tools logo