fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <ctime>
  7. #include <cstdlib>
  8. using namespace std;
  9.  
  10. class discgame
  11. {
  12. public:
  13. int radius;
  14. int randx;
  15. int randy;
  16. };
  17.  
  18. int main()
  19. {
  20. discgame disc1;
  21. discgame disc2;
  22. int xDist, yDist;
  23.  
  24. //Enters radiuses
  25. cout << "Enter c1 radius: ";
  26. cin >> disc1.radius;
  27. cout << "Enter c2 radius: ";
  28. cin >> disc2.radius;
  29. srand(time(0)); //ensures rand() generates new random numbers
  30.  
  31. //Throws c1
  32. cout << "Throwing c1" << endl;
  33. disc1.randx = rand() % 50 - 1; //generates a random number between 1 and 50 for where the disc will land
  34. disc1.randy = rand() % 50 - 1;
  35. cout << "Center at (" << disc1.randx << ", " << disc1.randy << ")." << endl;
  36.  
  37. //Throws c2
  38. cout << "Throwing c2" << endl;
  39. disc2.randx = rand() % 50 - 1;
  40. disc2.randy = rand() % 50 - 1;
  41. cout << "Center at (" << disc2.randx << ", " << disc2.randy << ")." << endl;
  42.  
  43. //Finds distances
  44. //distance = larger coordinate - smaller coordinate
  45. if (disc1.randx > disc2.randx) {
  46. xDist = disc1.randx - disc2.randx;
  47. }
  48. else {
  49. xDist = disc2.randx - disc1.randx;
  50. }
  51. cout << "Distance of centers on x-axis: " << xDist << endl;
  52. if (disc1.randy > disc2.randy) {
  53. yDist = disc1.randy - disc1.randy;
  54. }
  55. else {
  56. yDist = disc2.randy - disc1.randy;
  57. }
  58. cout << "Distance of centers on y-axis: " << yDist << endl;
  59.  
  60. //Checks for collision
  61. //distance must be smaller than all coordinates
  62. if ((xDist < disc1.randx) && (xDist < disc2.randx) && (yDist < disc1.randy) && (yDist < disc2.randy)) {
  63. cout << "Discs are overlapping. YOU WIN" << endl;
  64. }
  65. else {
  66. cout << "Discs are not overlapping. YOU LOSE" << endl;
  67. }
  68.  
  69. getchar();
  70. getchar();
  71. return 0;
  72. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:10: fatal error: 'conio.h' file not found
#include <conio.h>
         ^
1 error generated.
stdout
Standard output is empty