ArunS
I run program then I input x=10,y=5,z=15
output = 10
hmmmm double digits and single digit numbers do not work.
it seems that i was so happy with the program working with 1 digit xyz 2digits xyz but not 1 and 2 digits xyz.
ArunS
I run program then I input x=10,y=5,z=15
output = 10
hmmmm double digits and single digit numbers do not work.
it seems that i was so happy with the program working with 1 digit xyz 2digits xyz but not 1 and 2 digits xyz.
It is not a problem about single digit or double digit, it is just about the code logic. Again, what you want to check in your if and if else statement is for example x > y AND x > z which is the logic translation for testing "is x bigger than y and bigger than z?". Try to use that condition in your code for each if and if else, and you'll see that it should work.
HomePort : A C Web Service API for heterogeneous home automation systems
omg, what sorcery it this.
output is 5??????????????????????
lol that was all. x>y>z on the first if
OH I SEE. omg I look so ..............
thanks guys.
edit
more problems...............omg ill try to figure it out.
Last edited by langamer101; 01-18-2012 at 08:03 AM.
we have concentrated only for x, you have to do it in a same way for y and z conditions, thats all.
it this code correct now?. I run it, put aruns x=10,y=5,z=15 and x=5,y=4,z=6 and works.
Code:#include<stdio.h> #include<conio.h> main() { clrscr(); int x,y,z,l; printf("Enter value for x: "); scanf("%d",&x); printf("Enter value for y: "); scanf("%d",&y); printf("Enter value for z: "); scanf("%d",&z); if (x>y>z) printf("The large number is %d", x); else if (z>y) printf("The large number is %d", z); else if (y>x) printf("The large number is %d", y); else if (x>z) printf("The large number is %d", x); else printf("all values are the same"); getch(); return(0); }
Last edited by langamer101; 01-18-2012 at 08:15 AM.
First, I did not notice from the beginning, but take some time to read this page.
Then "x>y>z" is not good, that is not the proper way to do it. You have to compare if x>y AND x>z, by using the AND logic operator, which is "&&" in C.
Also, as ArunS mentioned, you have to apply this logic for all of the other statement.
At that point, and without trying to be mean, I think following a C tutorial would be a good idea for you. You will then understand much better about the theory and the syntax of the C language, and you will be able to solve this kind of problems in 5 minutes.
HomePort : A C Web Service API for heterogeneous home automation systems
ummm, hmm, thanks.
time to start reading and quiz myself on C tutorial.
my teacher has not taught me about "&&, ||, !" logical operators yet.
only these ">,<,=,==,>=,<=" relational operators.
Last edited by langamer101; 01-18-2012 at 08:38 AM.
It is actually possible to make it without the "&&", but then the logic will be different.
I usually don't like to give so detailed answer, but you seem like you thought quite a lot, so I will make an exception .
Here is what you could do :
-Assign the x value to l.
-Test if l is lesser than y.
-If yes
-Assign the y value to l.-If no ...
-Test if l is lesser than z.
-If yes, then z is the biggest.
-If no y is the bigest.
I think you can find the rest by yourself.
Last edited by Tibo-88; 01-18-2012 at 08:45 AM. Reason: Bad indent
HomePort : A C Web Service API for heterogeneous home automation systems
here is code now with && logical operator
tibo Ill try this x value to l and so on what you postedCode:#include<stdio.h> #include<conio.h> main() { clrscr(); int x,y,z,l; printf("Enter value for x: "); scanf("%d",&x); printf("Enter value for y: "); scanf("%d",&y); printf("Enter value for z: "); scanf("%d",&z); if (x>y && x>z) printf("The large number is %d", x); else if (z>y && z>x) printf("The large number is %d", z); else if (y>x && y>z) printf("The large number is %d", y); else printf("all values are the same"); getch(); return(0); }