I'm having a problem with a program of mine at the moment. Basically, the thought process was to see if the input was whether an int or a string. But as soon as I tried to test it out, it produced an error along the lines of "could not convert 'string' from std::string to bool"
Much help would be appreciated.
Here's the code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <string> words(9);
words[0] = "One";
words[1] = "Two";
words[2] = "Three";
words[3] = "Four";
words[4] = "Five";
words[5] = "Six";
words[6] = "Seven";
words[7] = "Eight";
words[8] = "Nine";
vector <int> numbers(9);
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
numbers[3] = 4;
numbers[4] = 5;
numbers[5] = 6;
numbers[6] = 7;
numbers[7] = 8;
numbers[8] = 9;
string word;
int number;
if (number) { // Check if the input is a number.
while (cin >> number) {
for (int x = 0; x < words.size(); x++)
if (number == x)
cout << "The number when stated in words is: " << words[x-1] << endl;
}
}
else if (word) { // This is the problem. Purpose is to check if the input is a string.
while (cin >> word) {
for (int y = 0; y < numbers.size(); y++)
if (word = words[y-1])
cout << "The word when stated in a number is: " << numbers[y-1] << endl;
}
}
}