I am new to programming . I tried to implement a sample program but it gives me a run time error.but height property is a float type one.
format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double’
#include<stdio.h>
#include<string.h>
struct user
{
char name[30];
float height;
/*float weight;
int age;
char hand[9];
char position[10];
char expectation[10];*/
};
struct user get_user_data()
{
struct user u;
printf("\nEnter your name: ");
scanf("%c", u.name);
printf("\nEnter your height: ");
scanf("%f", u.height);
return u;
};
int height_ratings(struct user u)
{
int heightrt = 0;
if (u.height > 70)
{
heightrt =70/10;
}
return heightrt;
};
int main(int argc, char* argv[])
{
struct user user1 = get_user_data();
int heighRate = height_ratings(user1);
printf("your height is ", heighRate);
return 0;
}
Your scanf() calls have format mismatch problems:
scanf("%c", u.name);
should bescanf("%s", u.name);
%s
to scan a string whereas%c
is used to scan a char.and
scanf("%f", u.height);
should bescanf("%f", &u.height);
Notice the
&
added. You need to pass the address of the float variable.