wanna correct this,, simple

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
71
72
73
74
#include <cstdlib>
#include <iostream>
#include <string>
#include "windows.h"
using namespace std;

int main()
{
    cout  << ">";
    string greeting1 ="Hey";
    string greeting2 ="hey";
    string greeting3 ="Sup?";
    string greeting4 ="Hello";
    string response1 ="Good";
    string response2 ="Bad";
    string response3 ="Not great";
    string input;
    cin >> input;
    
    if (input == greeting1)
    {
          cout << "hello, how are you?" << endl;
          cout << ">";
    }
    else if(input == greeting2)
    {
          cout << "How's it going?" << endl;
          cout << ">";
    }
    else if(input == greeting3)
    {
          cout << "Not much, waiting for someone to talk to" << endl;
          cout << ">";
    }
    else if(input == greeting4)
    {
          cout << "Hi, My name is ARC";
          cout<<".";
          Sleep(300);
          cout<<".";
          Sleep(300);
          cout<<".";
          Sleep(300);
          cout<<"." << endl;
          Sleep(300);
          cout << "ARC stands for Artificial Robot Companion.";
          Sleep(300);
          cout<<".";
          Sleep(300);
          cout<<".";
          Sleep(300);
          cout<<"." << endl;
          cout << "How are you today?" << endl;
          cout<<">";
          }
          cin >> input;
          if(input == response2)
          {
          cout << "I'm sorry to hear that, wanna talk about it?" << endl;
          main();
          }
          else if(input == response1)
          {
          cout << "Good! I' glad to hear your doing well!" << endl;
          main();
          }
          else if(input == response3)
          {
          cout << "Eh, well I'm sorry, is there any way I can help?" << endl;
          main();
          }
          
}




I need to replace that last cin >> input; with a getline because response3 is a two word response, any thoughts?

tried to replace it with getline(cin, input); but i must not get what i'm doing
Last edited on
getline should work. What was wrong with it?
program just closes immediately and didnt used to
Oh right. I was thinking of the first cin >> input.. To replace the second one with getline, but a cin.ignore() before it or just replace both of them. The reason is that cin >> leaves a newline in input stream which is picked up by getline as an empty line.

By the way, don recursively call main(). Use a loop instead.
ok that worked, now i need to make anything the user types in, lowercase.. so when they type Hey string greeting1="hey"; evaluates correctly
and i need to make it so that if string greeting="chicken"; and string greeting1="noodles";
and a user types chicken or noodles they get cout << "and dumplings"; maybe using strcmp somehow,, idk
Last edited on
Just convert the user input to all upper/lower case and then check it against the responses.

1
2
3
4
5
6
7
8
9
10
char ToLower(char input)
{
  //check input, convert to lower, return
}

//in main
for (int i = 0; i<someString.size(); i++)
{
    someString[i] = ToLower(someString[i]);
}


To convert char's to lower case, remember that char's are actually just numbers under the hood, so 1 if statement is all that would be required to check if a char is upper/lower. Check out this page (http://cplusplus.com/doc/ascii/) for the specs.
Topic archived. No new replies allowed.