I have three variables...
hours, minutes, minutes_remainders...
if hours, minutes and minutes_remainders are under 9...then I would like to have zeros in front of them...
rather then being 4...i want 04 displayed.
i did a If statement in C...
if (hours %26lt;= 9 || minutes %26lt;= 9 || minutes_remainder %26lt;= 9)
printf (" It is 0%d : 0%d : 0%d \n", hours, minutes, minutes_remainder);
but the thing is...
when I compile it, the statement only works for the first two conditions. I cannot seem to get the third condition for variable minutes_remainder correct...
WHAT DO I DO!!!!
How do I do a "IF STATEMENT" with three conditions in C programming language?
Your statement there shows logical OR for the arguments, so any of them will do the printf. You need to use parenthesis and logical and %26amp;%26amp; to do something like you are talking, I think.
Reply:You don't want to do the tests at all. Instead write each format as %2d. That will produce a minimum field width of 2 and will work where hours or minutes are one digit or two digits.
Reply:you can say :
x=1;
y=3;
if (x%26lt;%26gt;y)
cout%26lt;%26lt;"welcome"%26lt;%26lt;endl;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment