Question is a bit odd, didn't know how to word it.
My program is a dictionary vector with a cin at the end that will read your input and check if it's in the dictionary.
#include "std_lib_facilities_3.h"
#include <algorithm>
#include <string>
#include <iostream>
string translate_to_lower(string s)
{
transform(s.begi[/code]n(), s[/code].end(), s.begin(), (int (*)(int)) tolower);
return s;
}
int main()
{
vector<string>words(16);
string input;
words[0] = "hello";
words[1] = "world";
words[2] = "i";
words[3] = "a";
words[4] = "am";
words[5] = "the";
words[6] = "computer";
words[7] = "is";
words[8] = "was";
words[9] = "can";
words[10] = "do";
words[11] = "computation";
words[12] = "fast";
words[13] = "slow";
words[14] = "program";
words[15] = "c++";
cout << "Type in words!\nType ctrl + c to stop the program.\n";
while (cin>>input)
{
string translation = translate_to_lower(input);
int n = -1;
for ( int i=0; i<words.size(); ++i)
{
if (translation == words[i])
{
n=i;
}
else
{
}
}
if (n == -1)
{
cout << input << " was mispelled.\n";
}
}
}
How do I make the program accept inputs such as "hello?", "hello!", and "hello,"?
Last edited on
maybe it's your function
translate_to_lower
however check this code out
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 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <windows.h>
using namespace std;
int main()
{
vector<string>words(16);
char input[20] = {0};
words[0] = "hello";
words[1] = "world";
words[2] = "i";
words[3] = "a";
words[4] = "am";
words[5] = "the";
words[6] = "computer";
words[7] = "is";
words[8] = "was";
words[9] = "can";
words[10] = "do";
words[11] = "computation";
words[12] = "fast";
words[13] = "slow";
words[14] = "program";
words[15] = "c++";
cout << "Type in words!\nType ctrl + c to stop the program.\n";
while (cin>>input)
{
string translation = CharLower(input);
int n = -1;
for ( int i=0; i<words.size(); ++i)
{
if (translation == words[i])
{
n=i;
}
else
{
}
}
if (n == -1)
{
cout << input << " was mispelled.\n";
}
}
}
|
Last edited on