Hello, everyone! I recently started reading up on some code about 3 weeks ago. I've been slowly making my way through my textbook without too much difficulty. I've recently come across some problems that the textbook has been little to no help with. My main issue right now is that I can't seem to get some of my operators to work (or even become recognized) by Windows Studio. I've been working on a text-based game that requires the player to input their own responses without obvious guidance. Below is the code I have so far:
#include <iostream>
#include <string>
int main()
{
usingnamespace std;
string input1;
cout << "You wake up in your bed...\n";
getline(cin, input1);
int part1 = 0;
while (part1 < 1)
{
string look1 = "look";
string look2 = "look around";
string getup = "get up";
string close = "close";
if(input1 == look1)
{
cout << "A window, some other stuff.\n";
getline(cin, input1);
}
elseif(input1 == getup)
{
cout << "You get out of bed.\n";
input1+=1; // Moving on to the next prompt
}
elseif(input1 == close) // Same thing as earlier
{
cout << "The window is closed.\n";
getline(cin, input1);
}
}
return 0;
}
Anytime that I attempt to insert a "||" or "++" operator the program simply tells me that no operator matches that operand. This is making it difficult for me to continue because operators such as "||" are essential for giving the player more than one possible response to continue. Any advice?
I'd also like to mention that in C (and possibly in C++ if you chose the library for this), there is a function called close which could confuse the compiler when in the global namespace.
It doesn't here because the header for it is not included, so you're ok for now.
Just...close isn't a word you should use for a variable unless you've wrapped that in a namespace to avoid collision.
Thank you all for the quick responses! I couldn't find where in my book to find the proper formatting, I could only find the operators used alongside integers. Thanks for the helpful information and explanations. Also, I'll make sure to change the name of that variable as that definitely makes sense.