can you help me to answer this problem...


A high building has 26 floors with the level 0 and the level 25 as the lowest and the highest level, respectively. It has a lift for transport the occupant to the level destination. The lift moves up and down in respect to the current lift position.
You are asked to write a simple lift program to simulate the movement of the building occupants in the lift. The lift moves only to one level destination either up or down depending on the destination. Initially the lift position is at ground level or level 0. After arriving at each destination level, the user is asked whether to continue using the lift or not. If yes, the lift will resume running from its current position or current floor level. Example of program running (user input in bold):
Destination level: 5
You are moving up:
Level 1
Level 2
Level 3
Level 2
Level 5
You have arrived. See you again.
Again? (y/n): y
Destination level: 3
You are moving down:
Level 4
Level 3
You have arrived. See you again.
Again? (y/n): y
Destination level: 3
You are already at level 3.
Again? (y/n): n
THANK YOU!

Dani AI

Generated

Good assignment to practice loops, input validation, and off-by-one logic. Treat floors as the closed range [0,25]. Read a destination, compare to the current floor, then iterate toward it one level at a time. Only print the levels you pass through. Note the sample output jumps from Level 3 to Level 2 while moving up; that looks like a typo or a loop index bug. Keep the sequence strictly monotonic.

Here is a compact, standard C version you can build on. It validates input, clamps floors to the allowed range, and repeats until the user says no.

#include <stdio.h>

#define MIN_FLOOR 0
#define MAX_FLOOR 25

int main(void) {
    int current = 0;
    char line[64];

    for (;;) {
        int dest;

        printf("Destination level: ");
        if (!fgets(line, sizeof line, stdin)) break;
        if (sscanf(line, "%d", &dest) != 1) {
            puts("Please enter a number.");
            continue;
        }
        if (dest < MIN_FLOOR || dest > MAX_FLOOR) {
            printf("Please enter a level between %d and %d.\n", MIN_FLOOR, MAX_FLOOR);
            continue;
        }

        if (dest == current) {
            printf("You are already at level %d.\n", current);
        } else if (dest > current) {
            puts("You are moving up:");
            for (int f = current + 1; f <= dest; ++f) printf("Level %d\n", f);
            puts("You have arrived. See you again.");
            current = dest;
        } else {
            puts("You are moving down:");
            for (int f = current - 1; f >= dest; --f) printf("Level %d\n", f);
            puts("You have arrived. See you again.");
            current = dest;
        }

        printf("Again? (y/n): ");
        if (!fgets(line, sizeof line, stdin)) break;
        if (line[0] == 'n' || line[0] == 'N') { puts("THANK YOU!"); break; }
    }
    return 0;
}

Troubleshooting tips: if your loop prints a floor twice or out of order, check the start value (current + 1 when going up, current - 1 when going down) and the comparison operator. Avoid fflush(stdin); it is undefined in C. If you are stuck, post your attempt as suggested so folks can point out the exact fix. For unrelated Turbo C questions (like a receipt program), start a new thread, .

Recommended Answers

All 6 Replies

help me to make a reciept using turbo c

Wow. While I'm sure this isn't a record, one lazy student asking for "help"[1] on an assignment followed immediately by another lazy student hijacking the thread asking for "help" on an unrelated assignment is a wonderful example of the present progression toward the fall of Daniweb.


[1] "Help", of course, being loser's slang for "do it for me so I don't have to think".

Yes please post what you have so far. We appreciate a little effort on your part.

Wow. While I'm sure this isn't a record, one lazy student asking for "help"[1] on an assignment followed immediately by another lazy student hijacking the thread asking for "help" on an unrelated assignment is a wonderful example of the present progression toward the fall of Daniweb.


[1] "Help", of course, being loser's slang for "do it for me so I don't have to think".

Better than crying about fouls, why the moderators / owner of this forum is not taking steps to prevent these things happening?
So many things can be done like,
1. locking threads automatically after a certain time period so that no one bumps it up
2. Flagging threads to be deleted if they are violating the rules and delete them
3. Even banning the member if too much violations are done after warnings are given
4. Educating a new member about rules by making it mandatory for them to read the rules thread before posting the first thread...

etc
etc

options are endless
and some strong steps can 'save' this very useful forum...

>Better than crying about fouls, why the moderators / owner of
>this forum is not taking steps to prevent these things happening?

You think it hasn't come up countless times? There are a lot of smart people around here, and all of the big names I can think of have offered ideas for improving matters.

I've concluded that Dani simply doesn't care about the quality of the forum, only the activity. More members means more money; driving away the trash and dead weight is counterproductive to that goal.

>Better than crying about fouls, why the moderators / owner of
>this forum is not taking steps to prevent these things happening?

You think it hasn't come up countless times? There are a lot of smart people around here, and all of the big names I can think of have offered ideas for improving matters.

I've concluded that Dani simply doesn't care about the quality of the forum, only the activity. More members means more money; driving away the trash and dead weight is counterproductive to that goal.

Then it is a hopeless case!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.