Advertisement
EmmettMilligan

CPP Getch Method Exercise

Nov 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // base code file
  2.  
  3. #include <iostream>
  4. #include <windows.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #include <conio.h>
  8. #include <sstream>
  9. #include <fstream>
  10. using namespace std;
  11. void gotoxy(short x, short y) {
  12. COORD pos = {x, y};
  13. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  14. }
  15. // generates a random number between 0 and r inclusive
  16. int random(int r)
  17. {
  18. return rand()% r + 1;
  19. }
  20. ///////////////////////////////////////////////////////////////////////
  21. main()
  22. {
  23. srand(time(NULL));
  24. // write code here
  25. // leave the following line in all programs
  26. while(true){
  27. int randum = rand() % 100 + 1;
  28. cout<<"#######"<<endl;
  29. cout<<"# #"<<endl;
  30. cout<<"# #"<<endl;
  31. cout<<"# #"<<endl;
  32. cout<<"# #"<<endl;
  33. cout<<"#######"<<endl;
  34. gotoxy(3,2);
  35. cout<<randum;
  36. gotoxy(0,7);
  37. cout<<"Please enter q to quit. Any other chracter will allow you to continue:";
  38. char quit = getch();
  39. gotoxy(0,0);
  40. if(quit=='q'){
  41. break;
  42. }
  43. }
  44. getch();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement