undeclared Identifier

Apr 23, 2015 at 4:22am
My professor is having me write a chat bot and i keep getting an error saying "undeclared identifier." I am new to programming and could use some help.
this occurs on line 49.
sorry if this is hard to follow. i'm also new to the forum.

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
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <iostream> // for getline(), cout, cin
  #include <string>
  using namespace std;

  bool processInput(string); // prototype for user input function
  void idk (int); // prototype for misunderstood input

  int main()
  {
    // 1. declare and initialize variables
    bool keepgoing = true;
    bool understand = true;
    string userinput;
    string name;
    int (idontknow) = 1;
 //   cout << idontknow << endl;
    // 2. prompt for first input
    // . get name of user
    cout << "Hello, I am Chatbot. What is your name?\n" << "> ";
   getline (cin,name);
    cout << "Hello " << name << "!\n";
   // 3. while no response of "bye" or "Bye"
    while(keepgoing)
    {
        cout << "> ";
        // 3a. Get user input
        getline (cin,userinput);
        // 3b. Process user input and set keepgoing flag
        keepgoing = processInput(userinput);
    }
 }
  bool processInput(string userinput)
  // pre: userinput has been declared and initialized (can contain "")
  // post: chatbot response has been printed/output and true/false has been returned
 {
    if (userinput == "Hello" || userinput == "hello" || userinput == "hi") {

        cout << "We've already passed this part, can we move on?\n";
    }

    else if (userinput == "what is the meaning of life") {
    cout << "Easy!... 42";
    }

  //    cout << "you said ..." << userinput << endl;
  //    std::cout << "people who say that are idiots" << std::endl;
   else if (userinput == "Bye" || userinput == "bye") return false;

   else idk(int (idontknow));


    return true;

  }

  void idk(int (idontknow))
  {
    if (idontknow == 1) {
      cout << "I dont understand\n";
      }
    if (idontknow == 2) {
      cout << "Say what? I'm confused\n";
      }
    if (idontknow == 3) {
      cout << "I dont understand\n";
      idontknow = idontknow - 3;
      }
    idontknow++;
  }


thank you

Last edited on Apr 23, 2015 at 10:59am
Apr 23, 2015 at 4:36am
Could you fix your closing code tag and the line numbers?
Apr 23, 2015 at 10:15am
Is that better?
Apr 23, 2015 at 10:37am
Remove the line numbers and use the code tags correctly: [code]Your code[/code] --- Note the brackets.

You did not implement void idk (int)
Apr 23, 2015 at 11:01am
How exactly would you do that?
Apr 23, 2015 at 1:42pm
Remove the brackets from idontknow. In case of line 49 you would cast an int to an int.

To get different answers in idk you may write it like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  void idk() // Note
  {
    static int idontknow = 1; // Note

    if (idontknow == 1) {
      cout << "I dont understand\n";
      }
    if (idontknow == 2) {
      cout << "Say what? I'm confused\n";
      }
    if (idontknow == 3) {
      cout << "I dont understand\n";
      idontknow = idontknow - 3;
      }
    idontknow++;
  }


How exactly would you do that?
What?
Apr 23, 2015 at 1:57pm
When I remove the parentheses from (idontknow) it gives me an error "expected '(' for function-style cast or type construction" also on line 49. Or are you referring to something else?

How exactly would you do that?
How do you implement void idk (int)
Topic archived. No new replies allowed.