little problem

can someone take a look at this code and figure out whats missing and what it takes to fix it?? my friend gave it to me and i don't get what he is trying to accomplish


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
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

int main()
{

    string yourname;
    string greeting1 ="Hey";
    string greeting2 ="hey";
    string greeting3 ="Sup?";
    string greeting4 ="Hello";
    string input;
   // if (yourname=hasnovalueyet)
    {
    cout << "Welcome, please enter your name" << endl;
    cout <<">";
    getline(cin, yourname);
          cout << "Hello " << yourname <<". I will try to do my best to\nanswer anything you need help with" << endl;
    }
           cout << ">";
          cin >> input;
     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 " <<yourname<<". My name is ARC" << endl;
          cout << ">"; 
          main();
   }       
}


I know he doesn't know how to setup the yourname sections and from then on its just the if/elseif thats all messed up
It's missing a loop, mainly. The following will keep going until you type "Hey" (case-sensitive).

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
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string yourname;
  string greeting1 ="Hey";
  string greeting2 ="hey";
  string greeting3 ="Sup?";
  string greeting4 ="Hello";
  string input;
    
  cout << "Welcome, please enter your name" << endl;
  cout << ">";
  getline(cin, yourname);
  cout << "Hello " << yourname <<". I will try to do my best to\nanswer anything you need help with" << endl;

  do {
    cout << ">";
    cin >> input;
      
    if (input == greeting2){
      cout << "How's it going?" << endl;

    } else if(input == greeting3){
      cout << "Not much, waiting for someone to talk to" << endl;

    } else if(input == greeting4){
      cout << "Hi " <<yourname<<". My name is ARC" << endl;

    }
  } while (input != greeting1);

  return 0;
}
but it needs to be able to use all of those greetings
and want to implement something that does this
1
2
3
 if (cin != input){
    cout << "I'm sorry I didnt catch that, try asking in a different way.") << endl;
  main();
what i mean is
1
2
3
4
if (input = nothing){
    cout << "I'm sorry I didnt catch that, try asking in a different way.") << endl;
  main();
}
Last edited on
Topic archived. No new replies allowed.