Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <windows.h>
- #include <string>
- #include <fstream>
- #include <ctime>
- using namespace std;
- int main() {
- ifstream infile;
- ofstream outfile;
- char inputFilename[] = "in.txt";
- char outpitFilename[] = "out.txt";
- cout << "Input the path to the file to open, or input 0 to proceed." << endl;
- string inputcustom;
- cin >> inputcustom;
- int N = inputcustom.length();
- char inputcustom2[N];
- for (int m = 0;m < N; m++) {
- inputcustom2[m] = inputcustom[m];
- }
- if (cin.fail()) {
- cout << "Incorrect input. The program must be terminated." << endl;
- return 0;
- }
- end:
- cout << "Initial settings checked. Proceed by pressing 0." << endl;
- char x;
- cin >> x;
- if (x != '0') {
- cout << "Looks like you haven't pressed a 0. Try again." << endl;
- goto end;
- }
- if (inputcustom[0] != '0') {
- cout << "Custom file path chosen." << endl;
- infile.open(inputcustom2, ios::in);
- } else {
- infile.open(inputFilename, ios::in);
- }
- if (!infile) {
- cout << "Can't open the file." << endl;
- exit(1);
- }
- outfile.open(outpitFilename, ios::out);
- if (!outfile) {
- cout << "Can't open the output file." << endl;
- exit(1);
- }
- int id;
- int i = 0;
- string name;
- srand(time(NULL));
- i = rand()%15+rand()%10-rand()%15+rand()%10-rand()%20;
- i = abs(i);
- cout << "And the winning number is: " << i << endl;
- int iold = i;
- bool selectedwinner = false;
- while (infile >> id >> name) {
- id = abs(i+rand()%20-rand()%20);
- i++;
- outfile << id << "\t" << name << endl;
- cout << id << "\t" << name << endl;
- if (id == iold) {
- cout << "And we have a winner! Congratulations, " << name << endl;
- selectedwinner = true;
- }
- }
- if (selectedwinner == true) {
- cout << "Congratulations to the winners!" << endl;
- infile.close();
- outfile.close();
- }
- if (selectedwinner == false) {
- cout << "Seems like nobody was selected. Let's try again!" <<endl;
- infile.close();
- outfile.close();
- goto end;
- }
- cout << "The work is done." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement