Hi. My name is Tung. I just began study C++ and encountered some problem with it.
I am writing a program that can draw zigzag line. The length of the zigzag is depend on its width and users can set up the time for the line to be drawn.
I want to ask what is it mean when I have error:
-expected initializer before ':'
- was not declared in this scope
How can I fix it?
These are the problem that I encountered.
In function 'int main()':
zigzag.cpp:7:14: error: expected initializer before ':' token
zigzag.cpp:11:13: error: 'width' was not declared in this scope
zigzag.cpp:13:13: error: 'pausedtime' was not declared in this scope
zigzag.cpp:14:5: error: 'count' was not declared in this scope
zigzag.cpp:20:34: error: 'usleep' cannot be used as a function
zigzag.cpp:29:34: error: 'usleep' cannot be used as a function
This is my code
#include <iostream>
#include <unistd.h>
#include <iomanip>
using namespace std;
int main()
{
int width:
int pausedtime, count;
int usleep;
cout << "Enter the maximum field width: ";
cin >> width;
cout << "Enter the microseconds to pause between the arterisks: ";
cin >> pausedtime;
count = 1;
if (count <= width)
{
while (count <= width)
{
cout << "." << setw(count) << endl;
usleep(pausedtime);
++count;
}
}
else
{
while (count > width)
{
cout << "." << setw(count) << endl;
usleep(pausedtime);
--count;
}
}
return 0;
}
Thanks for your time.