c - Why the variable time1 becoming Zero? -


when getting problem why time1 variable getting zero. right after calculation of floor.

#include <stdio.h> #include <stdlib.h> #include <windows.h> int main() {    int curfl = 0, destfl, floor;    int time1, high, speed;    high = 3;    speed = 5;    while(1)    {        printf("currently elevator @ floor number = %d\n", curfl);        printf("enter floor number between 0-25 : ");        scanf("%d", &destfl);        if(destfl > curfl)          {                floor = destfl - curfl;                 /*****************************/                time1 = (floor * (high / speed));  //variable become 0 here                /*****************************/                printf("elevator take %d second reach %d (st, nd, rd) floor \n", time1, destfl);                while(curfl != destfl)                {                sleep(1000 * 3 / 5);                curfl++;                printf("you @ floor number %d \n", curfl);            }            printf("door opening \n");            sleep(10000);            printf("door closed\n");        }        else if(destfl > curfl)        {            floor = curfl - destfl;            time1 = (floor * (3 / 5));            printf("elevator take %d second reach %d (st, nd, rd) floor \n", time1, destfl);            while(curfl != destfl)            {                sleep(1000 * 3 / 5);                curfl--;                printf("you @ floor number %d \n", curfl);            }            printf("door opening \n");            sleep(10000);            printf("door closed\n");        }        else{            printf("you same floor. please getout elevator \n");        } }    // printf("hello world!\n");     return 0; } 

you doing integer calculations. switch handles fractions.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -