nope

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <unistd.h>
#include <stdlib.h> 
using namespace std;

int bar(float time){
    float progress=0.0;
    float inc=time/100;  
    while (progress<time) {
        float width=65;

        cout<<"[";
        float pos=width*progress;
        for (int i=0; i<width; i++) {
            if (i<pos)
                cout<<"#";        
            else 
                cout<<" ";
        }
        cout<<"]\r";
        cout.flush();
        usleep(250000);
        progress+=inc;
}
    cout<<endl;
}

int main(int argc, char* argv[]){
    float sec=atof(argv[1]);    
    if(sec>0){
        float ms=sec*1000000;
        cout<<bar(ms);
    }
}
Last edited on
2 things.

1. Your program does not compile at all. Can you update your code so it compiles?
2. Your program is missing the very first step. Let us address this before doing anything else, yes?

"Write a program which accepts a floating-point number as a command-line argument then delays for that number of seconds the ``usleep`` function). "


How do you write a program that accepts a command line argument?
What does "int argc, char** argv" mean in relation to this first instruction?
okay i believe the code is working now, at least it compiles for me
Topic archived. No new replies allowed.