businessesatoz
asked on
c++ zigzag pattern setw
Hello, i'm stuck ones again.... the code should generate a zigzag something like this
Please enter the maximum field width: 9
Enter the microseconds to pause between asterisks: 50000
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
^C
my code below kinds of works but i don't know what i'm doing wrong any help would be great thanks
Please enter the maximum field width: 9
Enter the microseconds to pause between asterisks: 50000
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
^C
my code below kinds of works but i don't know what i'm doing wrong any help would be great thanks
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main(void)
{
int width;
int interval;
cout <<"Please enter the maximum field width: ";
cin>> width;
cout <<"Enter the micrososeconds to pause between asterisks: ";
cin >> interval;
int n =1;
while (n <=width)
{
cout <<(setw(n)) << "*" <<endl;
n++;
}
while (true)
{
for(n =1; n<=width; n++)
cout << setw(n) <<"*" <<endl;
for(n=width; n > 1; n--)
cout << setw(n) <<"*" <<endl;
usleep(interval);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How could this program be stopped by entering Ctrl+C?
ASKER