C++ HELP!
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
string username, pass, rite, ritepass;
ritepass = "orjuela";
rite = "sergio";
cout << "enter username: ";
cin >> username;
cout << "enter password: ";
cin >> pass;
if (username == rite && pass == ritepass)
{
cout << "welcome ";
}
if (username ! rite) || (pass ! ritepass)
{
cout << "try again";
}
return 0;
}```
Can anyone tell me whats wrong with this?
my errors :(
C:\Documents and Settings\Sergio\Desktop\c++\username.cpp In function `int main(int, char**)':
19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected `)' before '!' token
19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp could not convert username' to
bool'
19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected primary-expression before '||' token
19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected `)' before '!' token
23 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected `;' before "return"
Renaming "rite" wont work :(
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
string username, pass, rite, ritepass;
ritepass = "orjuela";
rite = "sergio";
cout << "enter username: ";
cin >> username;
cout << "enter password: ";
cin >> pass;
if (username == rite && pass == ritepass)
{
cout << "welcome ";
}
return 0;
}
I deleted the bottom part, ran it then i got no errors but when i entered the "rite' username and password nothing happed it just closed. Someone please help me this is very frustrating!
SET wrote: In the if statment put a system("pause"); after welcome
If you wanted it to pause (or in a programming way : wait for key strokes), you can use one of the following functions : getch(), getche() or getchar().
And this is the right code for what you posted (or at least, cleaned from errors) :
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
string username, pass, rite, ritepass;
ritepass = "orjuela";
rite = "sergio";
cout << "enter username: ";
cin >> username;
cout << "enter password: ";
cin >> pass;
if (username == rite && pass == ritepass)
{
cout << "welcome ";
}
if (username != rite || pass != ritepass)
{
cout << "try again";
}
return 0;
}
i dont rly know if this can help but i made my own in ANSI/ISO model my problem is that when it come to the if and else part it dont look like to work.. but a least this code is clear from error :)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string username, password, lol, loltest;
username = lol;
password = loltest;
std::cout << " Enter your Username\n";
std::cin >> username;
std::cout << "Enter your Password\n";
std::cin >> password;
if (username == lol && password == loltest)
{
std::cout << "welcome\n";
return 0;
}
else
{
std::cout << "try again\n";
return 0;
}
}
Crypto, what is the use of writing this
markupusing namespace std;
when you are going to do this?
markupstd::cout
edit:
Is this what you were trying to do? I did not understand what your program was meant to do.
#include <iostream>
int main()
{
string username, password;
std::cout << "Enter your Username:";
std::cin >> username;
std::cout << endl;
std::cout << "Enter your Password:";
std::cin >> password;
std::cout << endl;
if (username == "lol" && password == "loltest")
{
std::cout << "welcome\n";
}
else
{
std::cout << "try again\n";
}
getchar();
return 0;
}
in case you didnt get what everyone is saying here is what your end code should look like (based on suggestions)
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { string username, pass, rite, ritepass; ritepass = "orjuela"; rite = "sergio"; cout << "enter username: "; cin >> username; cout << "enter password: "; cin >> pass;
if (username == rite && pass == ritepass) { cout << "welcome " << endl; } else { cout << "Wrong" << endl; } system("PAUSE"); return 0; }
good luck
daniel11us wrote: in case you didnt get what everyone is saying here is what your end code should look like (based on suggestions)
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { string username, pass, rite, ritepass; ritepass = "orjuela"; rite = "sergio"; cout << "enter username: "; cin >> username; cout << "enter password: "; cin >> pass;
if (username == rite && pass == ritepass) { cout << "welcome " << endl; } else { cout << "Wrong" << endl; } system("PAUSE"); return 0; }
good luck
Guys… As I said, getch() would be much better, you can use it on different platforms, also without the "Press any key to continue…" string…
And I HAVE posted the working code, so no need to confuse the guy with namespaces, and shits! Case Closed.