I have a program that asks for your username then asks for your password, when i compile it, it gives me both options of the password being correct and wrong how could i fix this.
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int password;
password = 'billy';
if (password != 'billy');
cout<<"Access denied, try again"<<endl;
return 0;
}
you'll probably have to compile it yourself to see what im trying to say, any help would be appreciated. Ask me any questions you need because i know i was not very precise...
how could i prevent it from giving me an error saying that else without a previous if statement when there clearly is an if statement before the else statement...
how could i prevent it from giving me an error saying that else without a previous if statement when there clearly is an if statement before the else statement...
You had semicolons at the end of the if statements, these are actually interpreted as null statements. Also, always use braces, even if there is only 1 statement. This will save you one day when you add more code. You can see elaleph's code doesn't have the semicolons.