Row of Ascii Characters
Sep 18, 2017 at 2:53pm UTC
I am trying to display a row of Ascii characters (ref 219). But all it displays is one character. What am I doing wrong?
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
// Display row of Ascii Characters 219
#include <iostream>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
int main(void )
{
int x;
gotoxy(0,23);
for (int i=1;i<81;i++)
x = 219;
cout << (char )x ;
}
Sep 18, 2017 at 3:10pm UTC
Only line 25 is inside the for-loop.
Either use braces { } to enclose both lines 25 and 26 inside the loop body.
Or perhaps like this
1 2 3
gotoxy(0,23);
for (int i=1;i<81;i++)
cout << (char )219 ;
Sep 18, 2017 at 6:34pm UTC
Hi
Thank you for the prompt response. I forgot about the braces. But I prefer your last bit of code. It's a bit more concise and does the job perfectly.
Topic archived. No new replies allowed.