Advertisement
Feuerex

Feuerex- Giveaway code

Dec 4th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <windows.h>
  4. #include <string>
  5. #include <fstream>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.  
  12. ifstream infile;
  13. ofstream outfile;
  14. char inputFilename[] = "in.txt";
  15. char outpitFilename[] = "out.txt";
  16.  
  17. cout << "Input the path to the file to open, or input 0 to proceed." << endl;
  18. string inputcustom;
  19. cin >> inputcustom;
  20. int N = inputcustom.length();
  21. char inputcustom2[N];
  22. for (int m = 0;m < N; m++) {
  23.  
  24.  
  25. inputcustom2[m] = inputcustom[m];
  26. }
  27. if (cin.fail()) {
  28.     cout << "Incorrect input. The program must be terminated." << endl;
  29.     return 0;
  30. }
  31. end:
  32. cout << "Initial settings checked. Proceed by pressing 0." << endl;
  33. char x;
  34. cin >> x;
  35. if (x != '0') {
  36.     cout << "Looks like you haven't pressed a 0. Try again." << endl;
  37.     goto end;
  38. }
  39. if (inputcustom[0] != '0') {
  40.  
  41.  
  42.     cout << "Custom file path chosen." << endl;
  43. infile.open(inputcustom2, ios::in);
  44. } else {
  45. infile.open(inputFilename, ios::in);
  46. }
  47. if (!infile) {
  48.     cout << "Can't open the file." << endl;
  49.     exit(1);
  50. }
  51.  
  52. outfile.open(outpitFilename, ios::out);
  53.  
  54. if (!outfile) {
  55.     cout << "Can't open the output file." << endl;
  56.     exit(1);
  57. }
  58. int id;
  59. int i = 0;
  60. string name;
  61. srand(time(NULL));
  62. i = rand()%15+rand()%10-rand()%15+rand()%10-rand()%20;
  63. i = abs(i);
  64. cout << "And the winning number is: " << i << endl;
  65. int iold = i;
  66. bool selectedwinner = false;
  67. while (infile >> id >> name) {
  68.     id = abs(i+rand()%20-rand()%20);
  69.     i++;
  70.     outfile << id << "\t" << name << endl;
  71.     cout << id << "\t" << name << endl;
  72.     if (id == iold) {
  73.         cout << "And we have a winner! Congratulations, " << name << endl;
  74.         selectedwinner = true;
  75.     }
  76. }
  77. if (selectedwinner == true) {
  78.     cout << "Congratulations to the winners!" << endl;
  79.     infile.close();
  80. outfile.close();
  81. }
  82. if (selectedwinner == false) {
  83.     cout << "Seems like nobody was selected. Let's try again!" <<endl;
  84.     infile.close();
  85. outfile.close();
  86.     goto end;
  87. }
  88. cout << "The work is done." << endl;
  89.  
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement