I am trying to create a dictionary program, just for fun. I doubt I will ever get past twenty words. But this program has a problem. It always goes to the word, no matter what I type in, or press.
Here is the source code:

#include <iostream>

using namespace std;

int main(void)
{

    cout << "Search! Enter in a word that you would like to find the definition." << endl;
    cout << "If we can have it, we'll give you all we have on it." << endl;
    cout << "    (Note: You must spell your word correctly.)" << endl;
    cout << "Now press a key to start the program!" << endl;
    string start;
    getline(cin, start);
    if (start == "dfhbghkdabdhadvahdvadjahdvjdhdhjdvhhjdvhjhjj")
    {goto start;}
    else {goto start;}
    start:
    cout << "Choose a[nother] word!" << endl;
    string word;
    getline(cin, word);
    if (word == "close" or "Close" or "CLOSE"){
             return 0;}
    if (word == "C++" or "c++" or "C+" or "c+" or "C" or "c")
    {
             cout << "\"C++\" or \"C\" <noun> A programing platform language that is very famous, though a bit messed up." << endl;
             goto start;
             }
    else {cout << "This word does not currently exist. Please consider submitting it!" << endl;}
             goto start;
             }

Recommended Answers

All 7 Replies

Two question the first it why are you using goto? It is very bad practice and your noticing first hand the negative effects it can have. Secondly why haven't you just used a while loop instead of all this back and forth.
Thirdly how does this even compile? It has so many errors in it. Also your goto and string variable are the same change the variable name to something more appropriate like userInput.

The if should look more like this:

if(word == "C++" || word == "c++")

That sounds like what I was doing. It compiled fine. Thank you for replying, but please be more specific. Sorry; I am a noob to c++, I have had a web designing Adobe Flash job, so no time to learn c++.

I compiled it like the following, and it still didn't work. Now it will close the program if I press a key. If I type in a random thing, it will say, "Choose an[nother] word!" If I press the ENTER key, it will close. If I type in c++, or close, it will close. So the c++ part isn't working, but the other parts are, I guess. Here is the new source code:

#include <iostream>

using namespace std;

int main(void)
{

    cout << "Search! Enter in a word that you would like to find the definition." << endl;
    cout << "If we can have it, we'll give you all we have on it." << endl;
    cout << "    (Note: You must spell your word correctly.)" << endl;
    cout << "Now press a key to start the program!" << endl;
    string startt;
    getline(cin, startt);
    if (startt == "dfhbghkdabdhadvahdvadjahdvjdhdhjdvhhjdvhjhjj")
    {goto start;}
    else {goto start;}
    start:
    cout << "Choose a[nother] word!" << endl;
    string word;
    getline(cin, word);
    if (word == "close" or "Close" or "CLOSE"){
             return 0;}
    if (word == "C++" or "c++" or "C+" or "c+" or "C" or "c")
    {
             cout << "\"C++\" or \"C\" <noun> A programing platform language that is very famous, though a bit messed up." << endl;
             goto start;
             }
    else {cout << "This word does not currently exist. Please consider submitting it!" << endl;}
             goto start;
             }

I am trying to create a dictionary program, just for fun. I doubt I will ever get past twenty words. But this program has a problem. It always goes to the word, no matter what I type in, or press.
Here is the source code:

#include <iostream>

using namespace std;

int main(void)
{

    cout << "Search! Enter in a word that you would like to find the definition." << endl;
    cout << "If we can have it, we'll give you all we have on it." << endl;
    cout << "    (Note: You must spell your word correctly.)" << endl;
    cout << "Now press a key to start the program!" << endl;
    string start;
    getline(cin, start);
    if (start == "dfhbghkdabdhadvahdvadjahdvjdhdhjdvhhjdvhjhjj")
    {goto start;}
    else {goto start;}
    start:
    cout << "Choose a[nother] word!" << endl;
    string word;
    getline(cin, word);
    if (word == "close" or "Close" or "CLOSE"){
             return 0;}
    if (word == "C++" or "c++" or "C+" or "c+" or "C" or "c")
    {
             cout << "\"C++\" or \"C\" <noun> A programing platform language that is very famous, though a bit messed up." << endl;
             goto start;
             }
    else {cout << "This word does not currently exist. Please consider submitting it!" << endl;}
             goto start;
             }

if statements don't use the 'or". The correct operator is "||". Surprised the compiler didn't flag that as a syntax error.

What is going on? I believe the others helped you. If you look you should see 'Solved Thread' and press that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.