Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

This works on Turbo C++ I wonder why it doesn't work here

+1 vote
asked Oct 28, 2022 by bjorn gaemuel (130 points)

#include<stdio.h>
#include<conio.h>
#include<dos.h>

main()
{clrscr();
int cx_gbm;
printf(\"NEW YEARS COUNTDOWN\n");
cx_gbm=10;

do
{printf ("%d\n", cx_gbm);
cx_gbm--; delay (200);}
while (cx_gbm>=0);

for (int x_gbm=7;x_gbm>=0;x_gbm--)
{printf ("\boomBoomBoom\n");
delay(100);}

the output says 

main.c:3:9: fatal error: dos.h: No such file or directory
    3 | #include<dos.h>
      |         ^~~~~~~
compilation terminated.

2 Answers

0 votes
answered Nov 4, 2022 by MIKEY (150 points)
It doesn't work because they are different programs that are why and because of that.
0 votes
answered Nov 5, 2022 by Peter Minarik (86,180 points)

You just posted the answer yourself: the "dos.h" include does not exist. OnlineGBD is hosted on a Linux machine, hence this header is not available. So clrscr() and delay() are not recognized commands.

You can wait with the sleep() command instead. You provide the number of seconds to wait.

system("clear") could be used to clear the console.

The below could work fine on OnlineGDB (and any Linux):

#include<stdio.h>
#include<unistd.h>

int main()
{
    system("clear");
    printf("NEW YEARS COUNTDOWN\n");
    
    for (int countdown = 10; countdown >= 0; countdown--)
    {
        printf("%d\n", cx_gbm);
        sleep(1);
    }

    for (int countdown = 7; countdown >= 0; countdown--)
    {
        printf("BoomBoomBoom\n");
        sleep(1);
    }
    return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...