I'm trying to write a program that takes a user's input and use it to call a specific vector without using a long if
statement. For example, if a user were to input "silver"
, I would like the program to call on the vector named silver
. This way, the user can select a specific vector simply by typing a word in.
Is there any way to do this while avoiding if
statements? My full program calls on lots of colors that the user inputs, and making if
statements for all of them would be tedious.
#include <iostream>
#include "cmath"
#include <vector>
using namespace std;
int main() {
string color1;
vector<double> gold = {0, 0, pow(10, -1), .95, 1.05};
vector<double> silver = {0, 0, pow(10, -2), .9, 1.10};
cout << "input color:";
cin >> color1;
return 0;
}