In short I want to have a list of names in a .txt (or whatever) file and pull from a line number. In my prog I got random to pick 3 dif numbers. From those numbers I would like to pull from a outside fill and input that name. I went the long way with the only way I could figure it out.
one = rand() % 5 + 1;
loop2:
two = rand() % 5 + 1;
if (one == two) goto loop2;
loop3:
three = rand() % 5 + 1;
if (three == one) goto loop3;
if (three == two) goto loop3;
cout << "F One, Marry One, Kill One\n";
if (one == 1 || two == 1 || three == 1) cout << " Rosie Huntington Whiteley ";
if (one == 2 || two == 2 || three == 2) cout << " Olivia Munn ";
if (one == 3 || two == 3 || three == 3) cout << " Katy Perry ";
if (one == 4 || two == 4 || three == 4) cout << " Cameron Diaz ";
if (one == 5 || two == 5 || three == 5) cout << " Mila Kunis ";
string f, marry, kill;
cout << "\n";
cout << "Who would you f? ";
cin >> f;
cout << "Who would you marry? ";
cin >> marry;
cout << "Who would you kill? ";
cin >> kill;
cout << "You would F " << fuck << "! Marry " << marry << "! and Kill " << kill << "!\n";
cout << "Another press 1, Quit press 2 ";
cin >> nmbr;
if (nmbr == 1) goto loop1;
return 0;
}
Also at the end of the loop how would I add an else so if any key but 2 was hit it would just say error. Now if you hit a number besides 1 it ends. If you hit a letter it goes into super glitch repeat mode. Not sure if it matters but I am using gedit and g++.
Wow good example of why gotos are called spaghetti junction. I had to reread it a lot.
Try to use methods a lot more. If you can write it without a goto then you might find the repeating goes away. e.g. Each piece of code that has any new purpose should go in to a new method.
Rather than using srand what you could do is use .getline until the current milliseconds are under or over certain amount. That will avoid counting lines and so on. I am not saying it is the best way forward, but it is outside the square.