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 38 39 40 41 42 43 44
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }
int main()
{
vector <string> values = { "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine" };
vector <int> values_n = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
string val = " ";
cout << "Enter any number from 'one' to 'nine': ";
cin >> val;
for (;;)
{
auto result = find(begin(values), end(values), val);
if (result != end(values))
{
cout << val << ": " << values_n[(result - values.begin())] << endl;
cout << "Enter any number from 'one' to 'nine': ";
cin >> val;
}
else
{
cout << "Error.\n";
cout << "Enter any number from 'one' to 'nine': ";
cin >> val;
}
}
system("PAUSE");
return 0;
}
|