Monday, July 27, 2009

Hello , In my C program scanf statement is not been accepted . I am working in LINUX system .?

#include%26lt;stdio.h%26gt;


main()


{


int hard,car_con,ten_str;





printf("Give the hardness of the steel\n");


scanf("%d",%26amp;hard);


printf("Give the carbon content of the steel\n");


scanf("%d",%26amp;car_con);


printf("Give the tensile strength of the steel\n");


printf("TEST1\n");


scanf("%d",%26amp;ten_str);


printf("TEST2\n");





if(hard%26gt;=50 %26amp;%26amp; car_con%26lt;=0.7 %26amp;%26amp; ten_str%26gt;=5600)


printf("Steel is of grade 10\n");





else if (hard%26gt;=50 %26amp;%26amp; car_con%26lt;=0.7%26amp;%26amp; ten_str%26lt;=5600)


printf("Steel is of grade 9\n");





else if(hard%26lt;=50 %26amp;%26amp; car_con%26lt;=0.7 %26amp;%26amp; ten_str%26gt;=5600)


printf("Steel is of grade 8\n");





else if(hard%26gt;=50 %26amp;%26amp; car_con%26gt;=0.7 %26amp;%26amp; ten_str%26gt;=5600)


printf("Steel is of grade 7\n");





else if(hard%26gt;=50 %26amp;%26amp; car_con%26gt;=0.7 %26amp;%26amp; ten_str%26lt;=5600 ||hard%26lt;=50 %26amp;%26amp; car_con%26lt;=0.7 %26amp;%26amp; ten_str%26lt;=5600 || hard%26lt;=50 %26amp;%26amp; car_con%26gt;=0.7 %26amp;%26amp; ten_str%26gt;=5600 )


printf("Steel is of grade 6\n");





else if(hard%26lt;=50 %26amp;%26amp; car_con%26gt;=0.7 %26amp;%26amp; ten_str%26lt;=5600)


printf("Steel is of grade 5\n");





THE ABOVE C PROGRAM IS NOT ACCEPTING SCANF STATEMENT BETWEEN TEST1 AND TEST2 ;scanf("%d",%26amp;ten_str);

Hello , In my C program scanf statement is not been accepted . I am working in LINUX system .?
What Linux distribution are you running? I'm asking this, because on some distro's you must include the PATH to where the header files are located, when compiling the source code! (specifying the -I flag like this: gcc -I/usr/openwin/include ...)!


I know some distributions where some header files which were supposed to be in the standard where located elsewhere as they normally should!
Reply:if that is the only error - comment it out and give ten_str a value for the time being.
Reply:I added this after yoru inputs:


printf("hard %d\n", hard );


printf("car_con %d\n", car_con );


printf("ten_str %d\n", ten_str );





And all is input correclty.





Your problemn is that you want floating point input and variables (clue: ...car_con%26lt;=0.7...).


You will need to declare floats as floats, not ints and adjust the scanf type specifiers as well.


No comments:

Post a Comment