How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".
Yes a string array could do what you want, or a switch statement. Also you could do this with a class builder/ constructor. Honestly though the string array would be the easiest
What I'm trying to figure out is, the user will enter a number and that number will be the corresponding array size consisting of different strings. A random number generator will generate integers that correspond to the array subscripts, which each subscript has it's own string word. Does this make sense?
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <algorithm>
int main()
{
// http://www.mochima.com/tutorials/vectors.html
std::vector<std::string> things ; // a resizeable array of names of things
std::size_t n ;
std::cout << "number of things? " ;
std::cin >> n ;
std::cout << "please enter " << n << " nouns\n" ;
std::string str ;
while( things.size() < n )
{
std::cin >> str ;
// http://www.cplusplus.com/reference/vector/vector/push_back/
things.push_back(str) ;
}
// the the sequence of things now contains things in the order
// they were entered by the user. now shuffle the sequence randomly
// so that each thing ends up in a random position
// http://www.cplusplus.com/reference/cstdlib/srand/
std::srand( std::time(0) ) ; // seed the rng
// http://www.cplusplus.com/reference/algorithm/random_shuffle/
std::random_shuffle( things.begin(), things.end() ) ;
// print out the random positions of things
for( std::size_t i = 0 ; i < things.size() ; ++i )
std::cout << i << ". " << things[i] << '\n' ;
}