Hi! I am a newbie at C++ and would love to have some help in solving this problem.

I have searched far and wide and watched videos on YouTube on how to put a space in between words but to no luck.

1
2
3
4
5
6
7
8
9
10
11
12
 case 4: //occurs when user inputs 4 in the 5 options given previously
                                {//Opening curly brace
                                    string input;// Declaration of this variable
                                    cout << "Hi there! I am CALE (Chatbot At Library Education), what can I help you with?" << endl ; //inserts new line and flushes stream, is displayed when user inputs 4
                                    while (input=="exit" );//Entry-controlled loop statement which allows user to to go back to the beginning when input "exit"
                                    {//Opening curly brace
                                     cin >> input ; //Prompts user to input "input"
                                    std::string sInput = ""; //input user concern here
                                    cout << "Okay! your concern is noted, Please wait for our library admin to get in touch with you soon. Thank you!" << endl ; //inserts new line and flushes stream
                                    }//Closing curly brace
                                }//Closing curly brace
                                        break;//Separates the execution of statements per labeled case so that there is no "fall-through" into the other statements 


What I need help is with case 4, with the CALE chatbot. I cannot seem to input spaces in between words as it causes errors in the program, thus needing to restart it every time the user puts a space. I would love to know your thoughts on this, thank you! This is the only thing in my code that causes errors, everything else works. Thank you in advance, my fellow humans. ^^
Last edited on
Instead of reading single token with operator>>, you can read the whole line with std::getline.

For example:
1
2
3
    std::string line;
    while (std::getline(line) && line != "please exit") {
    }
Last edited on
L5. The ending ; terminates the while statement. So if input is exit the lop will loop forever and if not exit the loop will exit immediately. You need to remove it. Shouldn't the condition be reversed - so that the while body executes when input is not exit?


Those code comments are horrid. They provide no clarity - only clutter. Some are flat out wrong (lines 7, 8).

@kbw
@seeplus
@booradley60

I thank you three for noticing my post and helping me with these concerns. I shall try your suggestions and get back to you! I am still a newbie and this is my first time coding something this long. I am still unsure why I need this for my college program as I am taking engineering that does not concern coding. Cheers to y'all!

I shall arrive with news by today.
Last edited on
Good morning!

Unfortunately, I did everything I could and was not able to make it on time for the defense. Thankfully, the professor was able to give us credit still and will try to guide us on how to fix it. I thank you guys for the helpful input. :) It means a lot! May you guys reach your goals and dreams, ciao!

Sincerely,
Hesh
Topic archived. No new replies allowed.