You are not logged in.

#1 2019-05-04 08:59:32

Gugi
Member
Registered: 2019-01-15
Posts: 23
Website

[SOLVED] C++ Error with sleep

Hello, today i finally decide with which program language i will code.
After few hours i finally get my first ERROR, and i want you to help me find way out smile

So at first point, my code have to count from 15 to 0 and after this says " Hell Yeah"

and from point where is no ERRORS it looks like:

#include <iostream>
#include <unistd.h>
#include <cstdlib>

using namespace std;

int main()

        {

        for (int i=15; i>=0; i--)
    {


            cout << i <<endl;
    }
        cout<<"Hell Yeah!";

        return 0;
        }

But when i want add

sleep(1000);

        system("clear");

Program should count from 15 to 0 and says Hell Yeah, but here i found my FIRST ERROR big_smile

#include <iostream>
#include <unistd.h>
#include <cstdlib>

using namespace std;

int main()

        {

        for (int i=15; i>=0; i--)
    {
      sleep(1000);

        system("clear");

            cout << i <<endl;
    }
        cout<<"Hell Yeah!";

        return 0;
        }

In my Console it looks like:
https://imgur.com/YfSBX2K

Any ideas why?

I am using Code:Blocks IDE and GNU GCC compiler, as TUTORIAL says.

Last edited by Gugi (2019-05-04 11:10:28)


- I am using Arch BTW

Offline

#2 2019-05-04 09:05:38

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] C++ Error with sleep

Read the Code of Conduct and only post thumbnails http://wiki.archlinux.org/index.php/Cod … s_and_code
Fix your title: https://wiki.archlinux.org/index.php/Co … ow_to_post


And posting screenshots of code output is pointless.


Moving to NC


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2019-05-04 09:16:07

ayekat
Member
Registered: 2011-01-17
Posts: 1,634

Re: [SOLVED] C++ Error with sleep

You tell your program to sleep for 1500 seconds (i.e. 25 minutes) before continuing. Have you waited for 25 minutes to see if it prints something?

Also, I recommend you try to format your code a bit more carefully (at least proper indentation of the code), to make things more readable (and spot mistakes more quickly).


pkgs │ hacks │ cfg │ blag

Online

#4 2019-05-04 09:27:14

Gugi
Member
Registered: 2019-01-15
Posts: 23
Website

Re: [SOLVED] C++ Error with sleep

ayekat wrote:

You tell your program to sleep for 1500 seconds (i.e. 25 minutes) before continuing. Have you waited for 25 minutes to see if it prints something?

Also, I recommend you try to format your code a bit more carefully (at least proper indentation of the code), to make things more readable (and spot mistakes more quickly).

thanks, i got this with your help, but still i got one error smile

with :

        system("clear");

it looks like in console:
   https://imgur.com/2Kw9tUD

#update

is this even possible in linux?

Last edited by Gugi (2019-05-04 09:39:08)


- I am using Arch BTW

Offline

#5 2019-05-04 09:39:50

ayekat
Member
Registered: 2011-01-17
Posts: 1,634

Re: [SOLVED] C++ Error with sleep

That would imply that the shell can't find `clear`, which seems rather odd. Does it work if you run the command from your shell directly?

Then again, as a more general C/C++ programming advice, using the system() call is not very clean anyway.
If your tutorial is telling you to use system() (and tells you to use an IDE for learning to code right away), I would advise using a different tutorial (but then again, that's a personal opinion).

Also, as already mentioned above, please don't paste text output as images.


pkgs │ hacks │ cfg │ blag

Online

#6 2019-05-04 09:47:24

Gugi
Member
Registered: 2019-01-15
Posts: 23
Website

Re: [SOLVED] C++ Error with sleep

ayekat wrote:

That would imply that the shell can't find `clear`, which seems rather odd. Does it work if you run the command from your shell directly?

Then again, as a more general C/C++ programming advice, using the system() call is not very clean anyway.
If your tutorial is telling you to use system() (and tells you to use an IDE for learning to code right away), I would advise using a different tutorial (but then again, that's a personal opinion).

Also, as already mentioned above, please don't paste text output as images.

Ok, i will not upload text output as images.

Yes, in my shell 'clear' works, so i dont have any idea why it wont works in code

Did you recommend any tutorials with #EasierWay ?


- I am using Arch BTW

Offline

#7 2019-05-04 10:44:45

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,691
Website

Re: [SOLVED] C++ Error with sleep

You will not be asked again.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#8 2019-05-04 11:13:42

Gugi
Member
Registered: 2019-01-15
Posts: 23
Website

Re: [SOLVED] C++ Error with sleep

WorMzy wrote:

You will not be asked again.

Its done,

Problem Solved


- I am using Arch BTW

Offline

Board footer

Powered by FluxBB