View Full Version: gotoxy example/prank/console status

C++ Learning Community > C++ Creations > gotoxy example/prank/console status


Title: gotoxy example/prank/console status
Description: good for scaring people.


ih8censorship - September 6, 2003 11:12 PM (GMT)
well in someones console program i was using a while back they had a percent thing that changed all the time and i thought oh thats neat i wonder if i could do that? so i tryed and made this little prank and came up with a cool little console status bar too.
CODE
#include <windows.h> // for windows cursor function
#include <iostream> // for cout
using namespace std;


void gotoxy(int x, int y) // this gotoxyfunction by josh woods
{
COORD coor; // X,Y coordinate handler
HANDLE hOutput; // get variable handler for screen
hOutput = GetStdHandle(STD_OUTPUT_HANDLE); // assign screen handler
coor.X = x; // assign coordinate X
coor.Y = y; // assign coordinate Y
SetConsoleCursorPosition(hOutput,coor); // call cursor position with screen handler and coordinates
}








void percentometer()
{

gotoxy (8,8);
cout << "Deleting C:\\";

gotoxy (13,10);
cout << "10%";
gotoxy(5,9);
cout<<"Û";// makes a block. also try other odd charachters like ° ±  ²
Sleep(1000);


gotoxy (13,10);
cout << "15%";
gotoxy(6,9);
cout<<"Û";
Sleep(1000);



gotoxy (13,10);
cout << "20%";
gotoxy(7,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "25%";
gotoxy(8,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "30%";
gotoxy(9,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "35%";
gotoxy(10,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "40%";
gotoxy(11,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "45%";
gotoxy(12,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "50%";
gotoxy(13,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "55%";
gotoxy(14,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "60%";
gotoxy(15,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "65%";
gotoxy(16,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "70%";
gotoxy(17,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "75%";
gotoxy(18,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "80%";
gotoxy(19,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "85%";
gotoxy(20,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "90%";
gotoxy(21,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (13,10);
cout << "95%";
gotoxy(22,9);
cout<<"Û";//5°±²
Sleep(1000);

gotoxy (13,10);
cout << "100%";
gotoxy(23,9);
cout<<"Û";//5°±²
Sleep(1000);


gotoxy (8,8);
cout << "C:\\ Deleted!";



}



int main() {

percentometer();
gotoxy(0,0);
system("pause");
return 0;
}


i tested it on dev c++ and vc++ 5.0 i know there is a gotoxy function in dev c++ in conio.h but i cant get it to work right for some reason but this works fine in dev c++ and vc++.

TheHawgMaster - September 7, 2003 12:36 AM (GMT)
The gotoxy in in conio.h was a DOS function, it doesn't work under Windows compilers. And couldn't you have made that code a million times shorter with a for loop?

ih8censorship - September 7, 2003 01:03 AM (GMT)
yeah i could have, but dident. i dont know why.

QUOTE
The gotoxy in in conio.h was a DOS function

oh thats why it wouldent work then. i thought i just got a buggy header or somethin :lol:

ZerO - December 8, 2003 05:47 PM (GMT)
Nice little program... I agree that a loop would be nice... But what is actualy the best way to make a loop.... And where can i put this little prank to scare people? :ph43r:

Mylu (noob) - February 21, 2004 08:56 PM (GMT)
QUOTE (ZerO @ Dec 8 2003, 05:47 PM)
Nice little program... I agree that a loop would be nice... But what is actualy the best way to make a loop.... And where can i put this little prank to scare people? :ph43r:

at the beggining at the code in the first
CODE
{
loop: //you can call it anythying ;)
//...otehr code
}
//then add this where you want it to loop

goto loop;


thats a way i nkow ehhe

TheHawgMaster - February 23, 2004 04:14 AM (GMT)
Whoa that's a terrible use of goto. Use a for loop.

FrozenKnight - February 23, 2004 07:53 AM (GMT)
CODE
#include <windows.h> // for windows cursor function
#include <iostream> // for cout
using namespace std;


void gotoxy(int x, int y) // this gotoxyfunction by josh woods
{
COORD coor; // X,Y coordinate handler
HANDLE hOutput; // get variable handler for screen
hOutput = GetStdHandle(STD_OUTPUT_HANDLE); // assign screen handler
coor.X = x; // assign coordinate X
coor.Y = y; // assign coordinate Y
SetConsoleCursorPosition(hOutput,coor); // call cursor position with screen handler and coordinates
}

void percentometer()
{
char* per = " 00%";

gotoxy (8,8);
cout << "Deleting C:\\";

for (int count = 1; count < 20; count++)
{
  gotoxy (13,10);
  per[1] = '0' + (char)count/2;
  per[2] = '0';
  cout << per;
  gotoxy(5+count++,9);
  cout<<"Û";// makes a block. also try other odd charachters like ° ±  ²
  Sleep(1000);

  gotoxy (13,10); //reuse for the 5% inc
  per[2] = '5';
  cout << per;
  gotoxy(5+count,9);
  cout<<"Û";// makes a block. also try other odd charachters like ° ±  ²
  Sleep(1000);
}

gotoxy (13,10);
cout <<  "100%";
gotoxy(26,9);
cout<<"Û";// makes a block. also try other odd charachters like ° ±  ²
Sleep(1000);

gotoxy (8,8);
cout << "C:\\ Deleted!";
}

int main()
{
percentometer();
gotoxy(0,0);
system("pause");
return 0;
}


My modification useing a loop. :) i know i could have used a stringstream but i didnt feel like it :þ

Edit: Status bar update

ih8censorship - February 23, 2004 08:49 PM (GMT)
wow just a few months ago i wrote that... yeah i would have wrote it much diferently had i done it now... isnt the only real "good" use for a goto a deeply nested loop? thats what i heard...

FrozenKnight - February 23, 2004 10:10 PM (GMT)
GOTO is for asm & basic it shoudln't be used with C++

user posted image

but gotoxy is a text displacement function and technically isnt a goto statement so it's allowed.

TheHawgMaster - February 23, 2004 10:56 PM (GMT)
Nah goto is the only way to get out of ugly nested loops. (Though nested loops should be avoided in general)




* Hosted for free by InvisionFree