I'm working on a formula calculator. In it, I've designated user controls (it's in a console). The script keeps track of the user inputs by assigning all user inputs concerning navigation into a string labeled 'ans'. However, I can't seem to get the 'if' and 'else' function to work with it. C++:
#include <conio.h>
#include <cstdlib>
using namespace std;
#include <iostream>
#include <string>;
#include <string.h>;
#include <sstream>;
int main()
{
begin:
cout << '\n';
cout << "Meh";
cout << '\n';
string ans; // U e I p t
cin >> ans;
cout << "input is "<<ans;
cout << '\n';
getline (cin, ans); // s r n u
if (ans == "begin"){
cout << "You typed begin";
_getch();
goto begin;
}
else{
cout << "You didn't type begin";
}
_getch();
goto begin;
return 0;
}
This is just a test script, not the full script. Using cout I've determined that it knows and remembers the 'ans' value is begin when entered, but the 'if' command says it isn't. Any help would be greatly appreciated, thanks!