Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (jadzia):

C language practice On line 25 (see below) it says that "unknown conversion type character 'y' in format", why is that?? and also, I don't think 'x/y' is not working right, so I used another variable z to represent it but I guess it doesn't work either (it keeps showing x=0)

OpenStudy (jadzia):

#include <stdio.h> #include<math.h> #include<stdlib.h> int main( int argc, char ** argv ) { int x; int y; int z; z= x / y; printf("Enter x value: \n"); fflush(stdout); scanf("%d",&x); printf("Enter y value: \n"); fflush(stdout); scanf("%d",&y); printf("Results: \n"); printf("x value\t |y value|expressions \t | results \n"); printf("%d \t | %d \t | x=y+3 \t | x= %d\n", x, y, y+3); printf("%d \t | %d \t | x=y-2 \t | x= %d\n", x, y, y-2); printf("%d \t | %d \t | x=y*5 \t | x= %d\n", x, y, y*5); printf("%d \t | %d \t | x=x/y \t | x= %d\n", x, y, z); printf("%d \t | %d \t | x=x % y \t | x= %d\n", x, y, x % y); return 0; }

OpenStudy (jadzia):

line 25 is printf("%d \t | %d \t | x=x % y \t | x= %d\n", x, y, x % y);

OpenStudy (jadzia):

Is there any other way to write this in a shorter way?

OpenStudy (e.mccormick):

That is already pretty short.

OpenStudy (rsmith6559):

The percent sign is a meta-character in printf format strings. To use a percent sign as a regular character, it must be escaped. The escape character in printf format strings is the percent sign, so: printf("%d \t | %d \t | x=x %% y \t | x= %d\n", x, y, x % y);

OpenStudy (jadzia):

Aah I see! Thank you again rsmith :D Thanks also e.mccormick for letting me know :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!