Okay guys, so I had to step away from my computer for a while and haven't been coding much, once I got back I decided to start learning Python and now I can't remember anything in C++. I should know how to do this but I just can't remember.. Anyways, I'm just trying to make a small console program that compares the user input to a string but like I said, I can't remember how this would be done.
This is what I'm stuck with now.
I think learning Python has tainted my brain because I'm trying to use Python syntax, and could have this easily written in Python, but I want to come back to C++.
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int main()
{
string password = ("C++PROGRAM");
cout << "Please enter your password" << endl;
//i want to get user input here
if {
USERINPUT == password;
cout << "Great! You now have full access!" << endl;
}
else {
cout << "Hmm.. That isn't correct!" << endl;
//if else loop back to cout << "Please enter your password"
}
return 0;
}
If you have written a lot of code with python and want to use them in your C++ sources. Here is a way to mix both languages together:
https://docs.python.org/2/extending/embedding.html
But this code is now faulty, I really need to just start over with C++ so I can understand what is wrong, because I don't understand why this is wrong..
Try this code yourself. I have included _getch() so you can see what is happening in the console before continuing.. If you insert the INCORRECT string - i.e. not C++PROGRAM, it just continues to the next line it doesn't loop back asking you to enter your password again.. But if you do insert the correct string ( password ) it will do the code inside of the while, meaning it will display "Hmm.. That isn't correct!".. Then on a new line it will also display, "Great! You now have full access".. Why is it doing this? I don't understand. Thank you for your time.