Thanks! you fixed up the code,
just the only thing is the input has a minimum of 5 inputs (sorry... i know its poor coding on my part... I just a beginner there is a lot I have to learn :( ), it was kind of why I used getline. But aside from that it seems to be working fine.
To be more precise I am making a guessing game.
This was my original script that I needed help with (i know its a mess a // a few things because those were lines I tried but commented out because they werent working):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
srand(time(0));
while(true){
//Vector taking some number of inputs
vector<string>animals;
string word;
cout << "Enter: ";
string input;
getline(cin,input);
if (input == "end") break;
animals.push_back(input);
if (animals.size() < 5) cout << "Enter At Last 5 Inputs: "; continue
vector<string>copy(animals);
random_shuffle(copy.begin(), copy.end());
// vector<string>selection;
// for (int i = 0; i < (rand()%3+1); ++i) {selection.push_back(copy[i]);};
// for (int k = 0; k < selection.size(); ++k) cout << selection.at(k); cout << endl;
string display;
for(int i =0; i <= rand()%3+1; ++i) display += copy.at(i);
// for (int i = 0; i < selection.size(); ++i) display += selection.at(i);
random_shuffle(display.begin(), display.end());
for (int k = 0; k < display.length(); ++k) cout << display.at(k); cout << endl;
}
return 0;
}
|
I need the program to:
1) Form a string vector from at least 5 user inputs (Vector 1)
2) Take from 1 to 3 random elements from above vector (Vector 2)
3) Copy Vector 2 to a temporary Vector or string
4) Shuffles this Copy Vector or string and displays
5) User then inputs the value
6) Checks Users Value
Example: Enter up to 5 inputs: alpha bravo charlie delta echo
Computer takes alpha and delta.
Output: What are the inputs in: palhdaetal
Input: alpha delta
Output: Correct!